-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoCo.java
More file actions
37 lines (34 loc) · 734 Bytes
/
GoCo.java
File metadata and controls
37 lines (34 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
37
/*
Goldbach's conjecture : Every even integer greater than 2 can be expressed as the sum of two primes.
Write a function which takes a number as input, verify if is an even number greater than 2 and also print atleast one pair of prime numbers.
*/
import java.util.*;
import java.io.*;
public class GoCo
{
public static void main(String args[])
{
int num = Integer.parseInt(args[0]);
if(num >2)
{
int i;
for(i=1; i < num/2;i++)
{
if(chkprime(i))
if(chkprime(num-i))
System.out.println(i+" "+(num-i));
}
}
}
private static boolean chkprime(int numb)
{
int max = (int)(Math.sqrt(numb));
int i;
for(i=2;i<=max;i++)
{
if((numb%i) == 0)
return false;
}
return true;
}
}