import java.util.Scanner;
public class Palindromes
{
public static boolean isPal(String s)
{
if(s.length() == 0 || s.length() == 1)
return true;
if(s.charAt(0) == s.charAt(s.length()-1))
return isPal(s.substring(1, s.length()-1));
return false;
}
public static void main(String[]args)
{
boolean quit = true;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word to test whether it is a palindrome or not. Type quit to end.");
String x = sc.nextLine();
while(quit) {
if(isPal(x))
System.out.println(x + " is a palindrome");
if else(x = quit)
quit = false;
else
System.out.println(x + " is not a palindrome");
}
}
}
im trying to create a program that Prompts the user to input a word or phrase, Allows the user to continue entering input until they choose to quit, has a recursive method to determine if the word or phrase entered is a palindrome, and prints a message that tells the user whether the word or phrase is a palindrome. i have most of this, but im not sure if i am going about it the right way. i tried to make it so that it would continue over and over again, but im getting an error on my if else statement ')' expected. if anyone has any advice or a solution it is much appreciated. thanks.

New Topic/Question
Reply



MultiQuote









|