-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoldbach.java
More file actions
61 lines (59 loc) · 1.4 KB
/
Copy pathGoldbach.java
File metadata and controls
61 lines (59 loc) · 1.4 KB
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
56
57
58
59
60
61
import java.util.*;
class Goldbach
{
int n;
Goldbach(int nn)
{
n=nn;
}
public void find()
{
for(int i=1;i<n;i=i+2)
{
int sum=0;
for(int j=1;j<n;j=j+2)
{
sum=i+j;
int check=0;
if(sum==n)
{
int check1=0;
int check2=0;
for(int k=1;k<=i;k++)
{
if(i%k==0)
check1++;
}
for(int k=1;k<=j;k++)
{
if(j%k==0)
check2++;
}
if((check1==2)&&(check2==2))
System.out.println(i+", "+j);
}
}
}
}
public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println("Enter the Number");
int n=Sc.nextInt();
if((n>9)&&(n<50))
{
if(n%2==0)
{
Goldbach ob=new Goldbach(n);
ob.find();
}
else
{
System.out.println("INVALID INPUT, NUMBER IS ODD");
System.exit(0);
}
}
else
System.out.println("INVALID INPUT, NUMBER IS OUT OF RANGE");
}
}