Created
November 19, 2015 07:56
-
-
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
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 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