Hey evereyone im new to the world of programming and forms of java help
but i just cant figure out the prob lem with my code.
I trying to check String input for a viable palindrome and it compiles but
i keep on getting the same run-time error.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 27
If anyone could help me suss it out it would be greatly appreciated.
MY CODE
//Jason 131002728;
//01;
//this class checks a String if its a palindrome;
//12-06-10;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//promt
System.out.println("Enter possible palindrome for testing");
String input = sc.nextLine();
//variables
int st = 0;
int fn = input.length();
char frontCh;
char backCh;
//checks a char from the first halve of the string
//to its reflective couterpart
while ((st != fn)||(st == input.length())) {
frontCh = input.charAt(st);
if (Character.isWhitespace(frontCh) == true) {
frontCh = input.charAt(st + 1);
}
backCh = input.charAt(fn);
if (Character.isWhitespace(backCh) == true) {
backCh = input.charAt(fn - 1);
}
if (frontCh != backCh) {
System.out.println("\nEntered String is NOT a palindrome!");
System.exit(0);
}
++st;
--fn;
}
//displays recognition of an acceptable palindrome
System.out.println("\nEntered String is a palindrome!");
}
}

New Topic/Question
Reply




MultiQuote




|