Palindrome String In Java

Here you learn palindrome string in java.

Palindrome string is a string where string remains same when reversed.

For example: dad, mom, madam, abcba, etc.,

example: Palindrome String In Java

Also Read – Palindrome Number In Java

import java.util.*;

public class Palindrome_String_In_Java {

public static void main(String[] args) {

String original;
String reverse = "";

Scanner sc = new Scanner(System.in);
System.out.println("Please enter a string to check: ");
original = sc.nextLine();
int number = original.length();

for(int a = number - 1;a >= 0;a--)
reverse = reverse + original.charAt(a);

if(original.equals(reverse))
System.out.println(original + " is a Palindrome string.");
else
System.out.println(original + " is not a Palindrome string.");
}
}

Output:

Palindrome String In Java

About the author

admin

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *