System.out.println("Please type a phrase below and see if its a palindrome:");
Scanner keyboard = new Scanner(System.in);
String phrase = keyboard.nextLine(); //0-7 char
int counter = 0; //0-7,1-6,2-5,3-4
String is = "";
int caseo;
while (counter < phrase.length()) {
int num = phrase.length() - (counter) - 1;
char a = phrase.charAt(counter);
char b = phrase.charAt(num);
++counter;
if (a == b) {
is = "a palindrome";
}
else {
is = "not a palindrome";
}
System.out.println("is " + is);
}
Aucun commentaire:
Enregistrer un commentaire