-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.java
More file actions
37 lines (33 loc) · 734 Bytes
/
new.java
File metadata and controls
37 lines (33 loc) · 734 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
package laioffer1;
public class class2quiz {
// Every even number greater than 2 can be expressed as the sum of two primes
// Check if this is true, starting from 4
public static void main(String arg[]) {
for (int i = 4; i<10000000; i+=20) {
if (!twosumprime(i)) {
System.out.println("GoldBach is not always right");
continue;
}
}
}
public static boolean twosumprime(int even){
for (int i = 2; i <= even/2; i++) {
if (isPrime(i) & isPrime(even-i)) {
return true;
}
}
return false;
}
public static boolean isPrime(int n) {
// Write your solution here
if (n == 2) {
return true;
}
for (int i = 2; i < n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}