forked from badal74/java-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion31.java
More file actions
23 lines (22 loc) · 720 Bytes
/
Copy pathquestion31.java
File metadata and controls
23 lines (22 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
class PalindromeExample2
{
public static void main(String args[])
{
String original, reverse = ""; // Objects of String class
Scanner in = new Scanner(System.in);
System.out.println("Enter a string/number to check if it is a palindrome");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
{
reverse = reverse + original.charAt(i);
}
if (original.equals(reverse))
{
System.out.println("Entered string/number is a palindrome.");
}
else
System.out.println("Entered string/number isn't a palindrome.");
}
}