String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 4/5

public static String run() {
    String s = "racecar";
    boolean p = true;
    for (int i = 0; i < s.length() / 2; i++) {
        if (s.charAt(i) != s.charAt(s.length() - 1 - i)) p = false;
    }
    return p ? "yes" : "no";
}
// Call: System.out.println(run());

What is printed?

  • A

    no

  • B

    yes

    check_circle
  • C

    true

  • D

    racecar

Explanation

Palindrome check; "racecar" is a palindrome.

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

Related questions