- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCheckPalindrome.java
More file actions
Latest commit
34 lines (27 loc) · 841 Bytes
/
Copy pathCheckPalindrome.java
File metadata and controls
34 lines (27 loc) · 841 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
/*
* Eden Ghirmai
* CheckPalindrome.java
*
* Checks if the string entered by the user is a palindrome.
* That is that it reads the same forwards as backwards like "racecar"
*/
importjava.util.*;
publicclassCheckPalindrome {
publicstaticvoidmain(String[] args) {
Scannerin = newScanner(System.in);
System.out.println("Palindrome Checker");
System.out.print("What phrase would you like to check? ");
Stringoriginal = in.nextLine();
Stringphrase = original.toLowerCase();
Stringbackwards = "";
for (inti = phrase.length() - 1; i >= 0; i--) {
Stringletter = phrase.substring(i, i + 1);
backwards += letter;
}
if (phrase.equals(backwards)) {
System.out.println(original + " is a palindrome!");
} else {
System.out.println(original + " is not a palindrome!");
}
}
}