I'm very new to programming and I'm in my first programming class. I was given a palindrome program and was asked to have the program test for palindromes while ignoring spaces and punctuation, I believe
that I am on track to get this done but I don't know where I have gone wrong, does anyone have any suggestions?
import java.util.Scanner; public class PalindromeTester { //----------------------------------------------------------------- // Tests strings to see if they are palindromes. //----------------------------------------------------------------- public static void main (String[] args) { String str, another = "y"; int left, right; Scanner scan = new Scanner (System.in); while (another.equalsIgnoreCase("y")) // allows y or Y { System.out.println ("Enter a potential palindrome:"); String input = scan.nextLine(); String strippedInput = input.replaceAll("\\W", ""); str = scan.nextLine(); } left = 0; right = str.length() - 1; while (str.charAt(left) == str.charAt(right) && left < right) { left++; right--; } System.out.println(); if (left < right) System.out.println ("That string is NOT a palindrome."); else System.out.println ("That string IS a palindrome."); System.out.println(); System.out.print ("Test another palindrome (y/n)? "); another = scan.nextLine(); } }