File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 12
12
*/
13
13
14
14
public final class GoldbachConjecture {
15
- private GoldbachConjecture (){
15
+ private GoldbachConjecture () {
16
16
}
17
17
18
18
/**
19
19
* Checks whether a number is prime or not
20
20
* @param n the input number
21
21
* @return true if n is prime, else return false
22
22
*/
23
- private static boolean isPrime (int n ){
23
+ private static boolean isPrime (int n ) {
24
24
int i ;
25
- if (n <= 1 || (n % 2 == 0 && n != 2 )){
25
+ if (n <= 1 || (n % 2 == 0 && n != 2 )) {
26
26
return false ;
27
27
}
28
28
else {
29
- for (i = 3 ; i < Math .sqrt (n ); i += 2 ) {
30
- if (n % i == 0 )
29
+ for (i = 3 ; i < Math .sqrt (n ); i += 2 ) {
30
+ if (n % i == 0 )
31
31
return false ;
32
32
}
33
33
}
34
34
return true ;
35
35
}
36
36
37
- public static void main (String [] args ){
37
+ public static void main (String [] args ) {
38
38
39
39
Scanner scanner = new Scanner (System .in );
40
40
System .out .println ("Enter a number" );
41
41
int n = scanner .nextInt ();
42
42
int flag = 0 ;
43
43
44
44
if (n %2 == 0 && n >2 ) {
45
- for (int i = 0 ; i <= n /2 && flag == 0 ; i ++)
45
+ for (int i = 0 ; i <= n /2 && flag == 0 ; i ++)
46
46
if (isPrime (i ))
47
- if (isPrime (n - i ))
47
+ if (isPrime (n - i ))
48
48
{
49
- System .out .println (format ("%d+%d= %d" , i , n - i , n ));
50
- flag = 1 ;
49
+ System .out .println (format ("%d + %d = %d" , i , n - i , n ));
50
+ flag = 1 ;
51
51
}
52
52
}
53
53
else
54
54
System .out .println ("Wrong Input" );
55
55
}
56
56
57
- }
57
+ }
You can’t perform that action at this time.
0 commit comments