-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome.java
37 lines (29 loc) · 1.01 KB
/
Palindrome.java
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
import java.util.Scanner;
public class Palindromi {
public static boolean palindrome(String text) {
String reversed = reverse(text);
return(text.equals(reversed));
}
public static String reverse(String text) {
String temp = "";
Integer inputLength = text.length() - 1;
// Integer counter = 0;
while (inputLength >= 0){
temp += text.charAt(inputLength);
inputLength--;
}
// write your code here
// note that method does now print anything, it RETURNS the reversed string
return temp;
}
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Type a text: ");
String text = reader.nextLine();
if (palindrome(text)) {
System.out.println("The text is a palindrome!");
} else {
System.out.println("The text is not a palindrome!");
}
}
}