Skip to content

Instantly share code, notes, and snippets.

@diegozr1
Created August 11, 2016 02:15
Show Gist options
  • Save diegozr1/0c8937fcca2af3fa5bddf810a1860bd4 to your computer and use it in GitHub Desktop.
Save diegozr1/0c8937fcca2af3fa5bddf810a1860bd4 to your computer and use it in GitHub Desktop.
Program to check if a word or phrase is Palindrome
public class palindrome {
/*
Compile it using javac palindrome.java
Runt it using java palindrome "anita lava la tina"
*/
public static void main(String args[]){
String d = args[0];
d = d.toLowerCase();
d = d.replaceAll("\\s","");
System.out.println(d);
char [] p = d.toCharArray();
Boolean aux = true;
for (int i = 0, t = d.length()-1; i<(Math.floor(d.length()/2)); i++,t--){
if (p[i] != p[t]){
aux = false;
}
}
if (aux){
System.out.println("Es Palindromo");
} else {
System.out.println("No es palindromo");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment