For my assignment I have to write and test a Java program to read in multiple lines of input until an empty line is read. After each line is read, I have to determine if the line contains a palindrome and, if it does contain a palindrome, I must print which type of palindrome it is (word, phrase, or number). In order to do the palindrome part I have to use a pseudo code.
The pseudo code is:
Note: in the following, the symbol represents assignment
left 0
right position of last character in string
okay true
while okay and left < right
ch1 character in the string at position (left)
if ch1 is not a digit or letter
increment left
else
ch2 character in the string at position (right)
if ch2 is not a digit or letter
decrement right
else
convert both ch1 and ch2 to upper case
if ch1 = ch2
increment left
decrement right
else
okay false
endif
endif
endif
end while
return okay
What I have so far is:
import java.util.Scanner;
public class Project4
{
public static void main (String [] args)
{
String line = getInputLine();
while (!isEmptyLine (line))
{
if (isPalindrome (line))
System.out.println ("\"" + line + "\" is a palindrome and a " + getPalType (line));
else
System.out.println ("\"" + line + "\" is not a palindrome");
line = getInputLine();
}
System.out.println ("End of program");
}
public static String getInputLine()
{
System.out.println("Enter a line of input: ");
Scanner in = new Scanner(System.in);
String line = in.next();
System.out.println(line);
return line;
}
public static boolean isEmptyLine (String str)
{
boolean isEmptyLine;
if( str == null)
isEmptyLine = true;
else
isEmptyLine = false;
return true;
}
public static boolean isPalindrome (String str)
{
Scanner word = new Scanner(System.in);
String isPalindrome = word.next();
int strLength = isPalindrome.length();
while(true && 0 < isPalindrome.charAt(isPalindrome.length() -1))
{
if(Character.isDigit(strLength) || Character.isLetter(0))
{
I have not finished it but I need help with understanding how to use the pseudo code. I don't quite understand the first if statement part. If anyone has time to explain the code I would greatly appreciate it.