AP Computer Science A Quiz
11 questions · no time limit
0:00
USING OBJECTS AND METHODS
Question 1 of 11
No time limit
Current
Answered
Flagged
Not seen
Palindrome Checker: What will be the output if the string is "Java"?
public class PalTool {
public static String check(String word) {
word = word.replace(" ", "");
String lower = word.toLowerCase();
String ends = lower.substring(0, 1).toUpperCase() + lower.substring(lower.length() - 1);
boolean isPal = true;
for (int i = 0; i < lower.length() / 2; i++) {
if (lower.charAt(i) != lower.charAt(lower.length() - 1 - i)) {
isPal = false;
}
}
return (isPal ? "PAL:" : "NOT:") + ends;
}
}
// Test case: System.out.println(PalTool.check("Java")); YOUR PROGRESS
11
QUESTIONS
Ready when you are
Answer in any order. Your progress shows here as you go.
QUESTIONS
KEYBOARD
Pick an answer ABCD
Next question ↵→
Previous ←
Flag for review F
Answers save as you go · flagged questions come back at the end