Skip to content

Commit 72ef2f9

Browse files
AC
Write function in java, compare character in string and get number in string
1 parent 17ad7f1 commit 72ef2f9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Number_beautiful_3.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.util.*;
2+
3+
public class Number_beautiful_3 {
4+
public static boolean Prime(int n) {
5+
if (n < 2)
6+
return false;
7+
else {
8+
for (int i = 2; i <= Math.sqrt(n); i++) {
9+
if (n % i == 0)
10+
return false;
11+
}
12+
}
13+
return true;
14+
}
15+
16+
public static void main(String[] args) {
17+
Scanner in = new Scanner(System.in);
18+
int T = in.nextInt();
19+
while (T-->0) {
20+
String s = in.next();
21+
int k = s.length();
22+
boolean check = true, check1 = true;
23+
for (int i = 0; i <= k / 2; i++) {
24+
if (s.charAt(i) != s.charAt(k - 1 - i)) {
25+
check = false;
26+
break;
27+
}
28+
}
29+
for (int i = 0; i < k; i++) {
30+
int tmp = Character.getNumericValue(s.charAt(i));
31+
if (Prime(tmp) == false) {
32+
check1 = false;
33+
break;
34+
}
35+
}
36+
if (check == true && check1 == true) {
37+
System.out.println("YES");
38+
} else {
39+
System.out.println("NO");
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)