Developing Algorithms Using Strings

AP Computer Science A· difficulty 3/5

public static boolean isPal(String s) {
  int i = 0, j = s.length() - 1;
  while (i < j) {
    if (s.charAt(i) != s.charAt(j)) return false;
    i++; j--;
  }
  return true;
}
// call: isPal("hello")

What does isPal("hello") return?

  • A

    0

  • B

    exception

  • C

    true

  • D

    false

    check_circle

Explanation

'h' != 'o', so the function returns false.

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

Related questions