-
Notifications
You must be signed in to change notification settings - Fork 3
/
_10945_MotherBear.java
44 lines (34 loc) · 1.07 KB
/
_10945_MotherBear.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
package io.github.tahanima.uva;
import java.util.Scanner;
/**
* @author tahanima
*/
public class _10945_MotherBear {
public static boolean isPalindrome(String word) {
int i = 0;
int j = word.length() - 1;
while (i < j) {
if (!Character.isLetter(word.charAt(i))) {
i++;
} else if (!Character.isLetter(word.charAt(j))) {
j--;
} else {
if (word.charAt(i) != word.charAt(j))
return false;
i++; j--;
}
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StringBuilder stringBuilder = new StringBuilder();
while (scanner.hasNextLine()) {
String word = scanner.nextLine();
if (word.equals("DONE"))
break;
stringBuilder.append(String.format("%s%n", isPalindrome(word.toLowerCase()) ? "You won't be eaten!" : "Uh oh.."));
}
System.out.print(stringBuilder);
}
}