-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBunkerArray_another.java
More file actions
34 lines (30 loc) · 933 Bytes
/
Copy pathBunkerArray_another.java
File metadata and controls
34 lines (30 loc) · 933 Bytes
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
public class BunkerArray_another {
public static void main(String[] args) {
System.out.println(isBunker(new int[]{7, 6, 10, 1}));
System.out.println(isBunker(new int[]{7, 6, 10}));
System.out.println(isBunker(new int[]{6, 10, 1}));
System.out.println(isBunker(new int[]{3, 7, 1, 8, 1}));
System.out.println(isBunker(new int[]{15, 8}));
}
static int isBunker(int[] a) {
boolean flagOne = false, flagPrime = false;
for(int element : a) {
if(element == 1)
flagOne = true;
else if(isPrime(element) == 1)
flagPrime = true;
if(flagOne && flagPrime)
return 1;
}
if(!flagOne && !flagPrime)
return 1;
return 0;
}
static int isPrime(int n) {
for (int i = 2; i <= n/2; i++) {
if (n % i == 0)
return 0;
}
return n > 1 ? 1 : 0;
}
}