- Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathString_Palindrome.java
More file actions
Latest commit
26 lines (20 loc) · 1.09 KB
/
Copy pathString_Palindrome.java
File metadata and controls
26 lines (20 loc) · 1.09 KB
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
importjava.util.Scanner;
classPalindrome_String {
publicstaticvoidmain(String[] args) {
ScannermyObj = newScanner(System.in); // Create a Scanner object
System.out.println("Enter username");
StringinputFromUser = myObj.nextLine(); // Reads the input and stores it in str
StringreverseInput = "";
intstrLength = inputFromUser.length(); // Assigns length of input string to variable
for (inti = (strLength - 1); i >= 0; --i) { // loop will execute till the end of the string
reverseInput = reverseInput + inputFromUser.charAt(i);
}
if (inputFromUser.toLowerCase().equals(reverseInput.toLowerCase())) { // checks if both reversed string and
// orignal string is equal
System.out.println(inputFromUser + " is a Palindrome String."); // print if its a palindrome
} else {
System.out.println(inputFromUser + " is not a Palindrome String."); // print if it is not palindrome
}
myObj.close();
}
}