Check palindrome string using Java.
In this programs to check whether the given String is Palindrome or not.
EXAMPLE :-
import java.util.Stack;
import java.util.Scanner;
class pali {
public static void main(String[] args) {
System.out.print("Enter The String ::");
Scanner in=new Scanner(System.in);
String inputString = in.nextLine();
Stack stack = new Stack();
for (int i = 0; i < inputString.length(); i++) {
stack.push(inputString.charAt(i));
}
String revString = "";
while (!stack.isEmpty()) {
revString = revString+stack.pop();
}
if (inputString.equals(revString))
System.out.println("The Input String is a palindrome.");
else
System.out.println("The Input String is Not a palindrome.");
}
}
OUTPUT
Enter The String ::abba
The Input String is a palindrome.
No comments:
Post a Comment
Please do not any spam link in Comment Box