- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeString.java
More file actions
Latest commit
22 lines (18 loc) · 563 Bytes
/
Copy pathPalindromeString.java
File metadata and controls
22 lines (18 loc) · 563 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
importjava.util.*;
classPalindromeString
{
publicstaticvoidmain(Stringargs[])
{
Stringoriginal, reverse = "";
Scannerin = newScanner(System.in);
System.out.println("Enter a string to check if it's a palindrome");
original = in.nextLine();
intlength = original.length();
for (inti = length - 1; i >= 0; i--)
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("The string is a palindrome.");
else
System.out.println("The string isn't a palindrome.");
}
}