Limited access

Upgrade to access all content for this subject

Which of the following methods will return the string characters in str in reverse order?

For example, if “pumpkin” is passed to it as the parameter, it should return “nikpmup”.

I.

    public static String backwardStringI(String str)    
    {
         String back = "";

         for (int i=str.length()-1; i>=0; i--)
         {
             back += str.substring(i);
         }
         return back;
    }

II.

    public static String backwardStringII(String str)
    {
         String back = "";

         for (int i=0; i<str.length(); i++)
         {
             back = str.substring(i, i+1) + back;
         }
         return back;
     }

III.

    public static String backwardStringIII(String str)    
    {
         String back = "";

         for (int i=str.length()-1; i>=0; i--)
         {
             back += str.substring(i,i+1);
         }
         return back;
    }
A

I only.

B

II only.

C

III only.

D

I and II only.

E

II and III only.

Select an assignment template