-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem39.java
49 lines (40 loc) · 969 Bytes
/
Problem39.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
package dimikOJ;
import java.util.Scanner;
public class Problem39 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while (t < 1) {
t = input.nextInt();
}
input.nextLine();
String[] inputs = new String[t];
for (int i = 0; i < t; i++) {
String temp = input.nextLine();
inputs[i] = temp.trim();
}
input.close();
for (int i = 0; i < inputs.length; i++) {
if (isPalindrome(inputs[i])) {
System.out.println("Yes! It is Palindrome!");
} else {
System.out.println("Sorry! It is not Palindrome!");
}
}
}
public static boolean isPalindrome(String s) {
boolean ans = false;
int j = s.length() - 1;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == s.charAt(j)) {
ans = true;
} else {
ans = false;
return ans;
}
j--;
}
return ans;
}
}