-
Notifications
You must be signed in to change notification settings - Fork 8
/
Palindromi.java
35 lines (30 loc) · 904 Bytes
/
Palindromi.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
import java.util.Scanner;
public class Palindromi {
public static String reverse(String text){
String reversed = "";
int i = text.length() - 1;
while (i >= 0){
reversed = reversed + text.charAt(i);
i--;
}
return reversed;
}
public static boolean palindrome(String text) {
// write code here
String textrev = reverse(text);
if (text.equals(textrev)){
return true;
}
return false;
}
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!");
}
}
}