I was working on this for a class assignment, and I cannot for the life of me get it to compile. I keep getting this error:
CPT236PalindromeCheckMethod.java:52: error: reached end of file while parsing } ^ 1 error
I have tried adding, removing, and checking all of my braces, but I cannot find anything wrong with it. I am new to programming, so I figured fresh eyes might help me find the issue.
import java.util.Scanner;
public class CPT236PalindromeCheckMethod {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();
if (checkPalindrome(s))
System.out.println(s + " is a palindrome");
else
System.out.println(s + " is not a palindrome");
}
public static boolean checkPalindrome(String str){
String lowerString = str.toLowerCase();
String resultString = "";
for(int i=0; i<lowerString.length(); i++) {
if(Character.isLetter(lowerString.charAt(i))) {
resultString = resultString + lowerString.charAt(i);
}
}
int low = 0;
int high = resultString.length() - 1;
boolean isPalindrome = true;
while (low < high) {
if (resultString.charAt(low) != resultString.charAt(high)) {
isPalindrome = false;
break;
}
low++;
high--;
}
}
You need a return value in the second method. It needs to return true or false. Return isPalindrome.
You should ideally use SublimeText or Eclipse. That way it'll debug your text realtime with JAVAC, and tell you where your errors are. It's much easier to troubleshoot realtime.