-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq37.java
More file actions
55 lines (49 loc) · 971 Bytes
/
q37.java
File metadata and controls
55 lines (49 loc) · 971 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import helpers.helpers;
import java.util.*;
public class q37 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0;
int sum = 0;
int value = 11;
while(count < 11){
if(containsEven(Integer.toString(value))){
value++;
continue;
}
if(isTrunc(value)){
System.out.println("Value: " + value);
sum += value;
System.out.println("New Sum: " + sum);
count++;
}
value += 2;
}
System.out.println("9 is prime: " +helpers.isPrime(9));
}
public static boolean containsEven(String s){
int a = 0;
for(a = 4; a < 9; a +=2){
if(s.contains(Integer.toString(a))) return true;
}
return false;
}
public static boolean isTrunc(int i){
//from the right
int ten = 10;
while(ten < i){
if(!helpers.isPrime(i%ten)){
return false;
}
ten *= 10;
}
//from left
while(i > 0){
if(!helpers.isPrime(i)){
return false;
}
i /= 10;
}
return true;
}
}