Question: java. comment both codes out for everyline. explain the code. will give thumps up import java.util.Scanner; public class Main { public static void main(String[] args)

java.
comment both codes out for everyline. explain the code. will give thumps up
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Palindrome Checker.");
System.out.println("Note: This palindrome checker is not case-sensitive and will ignore spaces.");
for (;;) {
System.out.print("Enter word (or 'quit' to exit): ");
String input = scanner.nextLine();
if (input.equals("quit")) {
break;
}
Deque deque = new Deque<>();
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (Character.isLetterOrDigit(ch)) {
deque.addBack(Character.toLowerCase(ch));
}
}
boolean isPalindrome = true;
for (; deque.length() > 1; ) {
char front = deque.removeFront();
char rear = deque.removeBack();
if (front != rear) {
isPalindrome = false;
break;
}
}
if (isPalindrome) {
System.out.println("Yes - That is a palindrome ");
} else {
System.out.println("No - That is not a palindrome ");
}
}
scanner.close();
}
}
//////////////////////////////////////////

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!