Last active
August 29, 2015 13:56
-
-
Save LordNairu/8904090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package practicalonep2.uk.ac.qub; | |
import java.util.Scanner; | |
public class Palindrome { | |
public static void main(String args[]){ | |
String original, reverse=""; | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Enter a word or sentence to check if it is a palindrome:"); | |
original = scanner.nextLine(); | |
scanner.close(); | |
int length = original.length(); | |
for ( int counter = length -1 ; counter >= 0 ; counter-- ){ | |
reverse += original.charAt(counter); | |
} | |
if (original.replaceAll("\\s+","").equalsIgnoreCase(reverse.replaceAll("\\s+",""))){ | |
System.out.printf("'%s' is a palindrome.",original); | |
}else{ | |
System.out.printf("'%s' is not a palindrome.",original); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment