Developing Algorithms Using Strings

AP Computer Science A· difficulty 2/5

String s = "hello";
String r = "";
for (int i = s.length() - 1; i >= 0; i--) {
  r += s.charAt(i);
}

What is r?

  • A

    hellohello

  • B

    olleh

    check_circle
  • C

    hello

  • D

    (empty)

Explanation

The loop appends chars in reverse, producing "olleh".

Want 10 more like this — adaptive to your weak spots?

Related questions