public class MyClass {
static boolean isPrime(int n) {
if (n < 2 || (n % 2 == 0 && n != 2)) {
return false;
}
int count = (int)Math.floor(Math.sqrt(n));
for (int i = 3; i <= count; i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
public static void main(String args[]) {
int n = 38;
boolean has_primes = false;
for (int i = 2; i <= n / 2; i++) {
if (isPrime(i)) {
if (isPrime(n - i)) {
System.out.printf("%d = %d + %d\n", n, i, n - i);
has_primes = true;
}
}
}
if (!has_primes)
System.out.println(n + " cannot be expressed as a sum of two prime numbers");
}
}
/*
run:
38 = 7 + 31
38 = 19 + 19
*/