Need help with while loops
I am supposed to write a program that asks the user to enter an English sentence, phrase or paragraph, and then test the input for various properties.
The program has to allow the user to enter a sentence (through a dialog), and will respond by telling the user the answer to the following questions:
Is the input a palindrome?
here is what i have so far:
public class Lab4
public static void main(Stringargs)
Scanner in = new Scanner(System.in);
String input ;
int length, pos1, pos2;
char char1, char2;
// Prompt, get, and save sentence
System.out.println("Please enter a sentence:");
input = in.nextLine();
System.out.println("Your input was: " + input + ".");
// Is the input a palindrome?
pos1 = 0;
if(char1 == char2)
else if (char1 == ',' || char1 == '.' ||
char1 == '-' || char1 == ':' ||
char1 == ';' || char1 == ' ')
else if (char2 == ',' || char2 == '.' ||
char2 == '-' || char2 == ':' ||
char2 == ';' || char2 == ' ')
if (pos1< pos2)
System.out.println ("That string is NOT a palindrome.");
System.out.println ("That string IS a palindrome.");
i dont understand what i'm doing wrong. i am comparing the last and first character and moving toward the center. i also attempted to make sure it skipped punctuation and spaces. can somebody please help me?