Limited access

Upgrade to access all content for this subject

Consider the following code segment.

String word = // assume word is pointing to a valid String and not null

Which of the following segments of code will NOT reverse the String that word is pointing to?

A
String reversed = "";
for (int i=0; i<word.length(); i++)
{
    reversed = word.substring(i,i+1) + reversed;
}
word = reversed;
B
String[] rev= new String[word.length()];
for (int i=0; i<word.length(); i++)
{
    rev[i]=word.substring(i,i+1);
}
word = "";
for (String c : rev)
{
    word = c + word;
}
C
reversed = "";
for (int i=word.length()-1; i>=0; i--)
{
    reversed = word.substring(word.length()-i-1, word.length()-i) + reversed; 
}
word = reversed;
D
reversed = "";
for (int i=word.length()-1; i>=0; i--)
{
    reversed += word.substring(word.length()-i-1, word.length()-i);
}
word = reversed;
E
reversed = "";
for (int i=0; i<word.length(); i++)
{
    reversed += word.substring(word.length()-i-1, word.length()-i);
}
word = reversed;
Select an assignment template