-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
38 lines (29 loc) · 833 Bytes
/
Palindrome.java
File metadata and controls
38 lines (29 loc) · 833 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
/**
* This class demonstrates the methods of the Palindrome class.
* @author Ioannis Tzeneralis
* @version 1.0
*/
class Palindrome {
/**
* This is the main method.
* @param args Unused.
*/
public static void main(String args[]) {
System.out.print("Enter any string:");
Scanner in = new Scanner(System.in);
String inputString = in.nextLine();
SC stack = new SC(inputString.length());
for (int i = 0; i < inputString.length(); i++) {
stack.push(inputString.charAt(i));
}
String reverseString; // Initialize String
while (!stack.empty()) {
reverseString = reverseString+stack.pop();
}
if (inputString.equals(reverseString))
System.out.println("The input String is a palindrome.");
else
System.out.println("The input String is not a palindrome.");
}
}