-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome.java
49 lines (34 loc) · 1001 Bytes
/
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
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
class Palindrome{
static boolean isPalindrome (String str){
str = str.toLowerCase();
str = str.replaceAll ("[^a-z]", ""); //pode ser uma frase
int size = str.length()-1;
for(int i=0; i<size; i++){
if (str.charAt(i)!=str.charAt(size))
return false;
size--;
}
return true;
}
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in); //Só posso ter um Scanner
int n = stdin.nextInt();
String vec[] = new String[n+1];
for (int j=0; j<=n; j++){
String str = stdin.nextLine();
boolean resultado = isPalindrome(str);
if(!resultado){
vec[j]="nao";
}
else{
vec[j]="sim";
}
}
System.out.println(n);
for(int k=1;k<=n;k++){
System.out.println(vec[k]);
}
stdin.close();
}
}