-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseDecimal.java
More file actions
43 lines (36 loc) · 1.19 KB
/
ReverseDecimal.java
File metadata and controls
43 lines (36 loc) · 1.19 KB
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
package array;
import java.util.ArrayList;
import java.util.Scanner;
public class ReverseDecimal {
public static ArrayList<Integer> solution1(int len, StringBuilder[] inputArray) {
ArrayList<Integer> result = new ArrayList<>();
for (StringBuilder i : inputArray) {
boolean isPrime = true;
int reverseInteger = Integer.parseInt(i.reverse().toString());
if (reverseInteger <= 1) {
continue;
}
for (int j = 2; j <= Math.sqrt(reverseInteger); j++) {
if (reverseInteger % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
result.add(reverseInteger);
}
}
return result;
}
public void main() {
Scanner in=new Scanner(System.in);
int len = in.nextInt();
StringBuilder[] inputArray = new StringBuilder[len];
for (int i = 0; i < len; i++) {
inputArray[i] = new StringBuilder(Integer.toString(in.nextInt()));
}
for (int i : solution1(len, inputArray)) {
System.out.print(i + " ");
}
}
}