?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Reverse the Order of Characters in String

APCSA-F6YD9W

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.