Skip to content

Instantly share code, notes, and snippets.

@eMahtab
Created November 19, 2015 07:56
Show Gist options
  • Save eMahtab/12956fe6f159d6a0b9c9 to your computer and use it in GitHub Desktop.
Save eMahtab/12956fe6f159d6a0b9c9 to your computer and use it in GitHub Desktop.
Java program to check whether a String is palindrome or not. e.g. madam is palindrome as the reverse of the word madam is also the same as actual word
public class PalindromeStringCheck{
public static void main(String ... args){
System.out.print("Enter a String : ");
String input=System.console().readLine();
String copyOfInput=input;
int i=0;
int j=input.length()-1;
boolean palindrome=true;
int loop=1;
while(loop <= (input.length()/2) ){
if(input.charAt(i) != input.charAt(j)){
palindrome=false;
break;
}
i++;
j--;
loop++;
}
if(palindrome){
System.out.println(copyOfInput+ " is Palindrome");
}else{
System.out.println(copyOfInput+ " is not Palindrome");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment