Trace: palindrome check indices 🌶️🌶️
Below is the loop from a palindrome checker for the String s = "level" (length 5). Trace the value of i and the matching index from the end on each iteration. Add a row for every iteration the loop actually executes — don't add a row once the loop condition fails.
boolean isPalindrome = true;for (int i = 0; i < s.length() / 2; i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { isPalindrome = false; }}
1. Trace i and s.length() - 1 - i for each iteration of the loop.
Add a row for each line or iteration you want to trace, in order. Fill in the value of each variable at that point, then check your work.
Your score for your class is recorded when you click Submit all — checking individual questions doesn't save it. You can submit again to improve your score; your best one counts.