Palindrome String in Java
Here, you will get and learn Palindrome String Program in Java programming.
Palindrome : A string that can be read same as, from forwards and backward is called a palindrome string.
For Example:- “racecar” and “madam” can be read the same as from forwards and backward. So they are palindrome string.
Palindrome String Program in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import java.util.Scanner; public class StringPalindrome { public static void main(String args[]) { String str, revStr = ""; Scanner in = new Scanner(System.in); System.out.println("Enter a string to check palindrome or Not : "); str = in.nextLine(); for (int i = str.length() - 1; i >= 0; i--) { revStr = revStr + str.charAt(i); } if (str.equals(revStr)) { System.out.println(str + " is a palindrome"); } else { System.out.println(str + " is not a palindrome"); } } } |
Output
Check out our other Java Programming Examples