/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome2.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package lab12_calebfontenot;
import java.util.Scanner;
public class Palindrome2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();
int low;
int high = s.length() - 1;
boolean isPalindrome = true;
for (low = 0; low < high; low++) {
if (s.charAt(low) != s.charAt(high)) {
isPalindrome = false;
break;
}
high--;
}
if (isPalindrome) {
System.out.println(s + " is a palindrome");
} else {
System.out.println(s + " is not a palindrome");
}
}
}