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("racecar")What does isPal("racecar") return?
- A
false
- B
null
- Ccheck_circle
true
- D
compile error
Explanation
"racecar" reads the same forwards and backwards.