Created
January 13, 2016 00:36
-
-
Save thmain/8f93ff6f0d53e67894f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GoldbachConjecture { | |
public static void Goldbach(int x) { | |
if (x % 2 != 0) { | |
System.out.println("Not Even"); | |
return; | |
} | |
if (x <= 2) { | |
System.out.println("Less than 2"); | |
return; | |
} | |
for (int i = 3; i < x / 2; i++) { | |
if (isPrime(i) && isPrime(x - i)) { | |
System.out.println("Prime Numbers are " + i + " " + (x - i)); | |
} | |
} | |
} | |
public static boolean isPrime(int x) { | |
for (int i = 2; i < x / 2; i++) { | |
if (x % i == 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
Goldbach(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
This code does not apply to 4 and 6 ,
starting the loops from 2 and ending with condition i <= x/2 will work fine 👍