Created
August 11, 2016 02:15
-
-
Save diegozr1/0c8937fcca2af3fa5bddf810a1860bd4 to your computer and use it in GitHub Desktop.
Program to check if a word or phrase is Palindrome
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
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