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 1212 */
1313
1414public final class GoldbachConjecture {
15- private GoldbachConjecture (){
15+ private GoldbachConjecture () {
1616 }
1717
1818 /**
1919 * Checks whether a number is prime or not
2020 * @param n the input number
2121 * @return true if n is prime, else return false
2222 */
23- private static boolean isPrime (int n ){
23+ private static boolean isPrime (int n ) {
2424 int i ;
25- if (n <= 1 || (n % 2 == 0 && n != 2 )){
25+ if (n <= 1 || (n % 2 == 0 && n != 2 )) {
2626 return false ;
2727 }
2828 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 )
3131 return false ;
3232 }
3333 }
3434 return true ;
3535 }
3636
37- public static void main (String [] args ){
37+ public static void main (String [] args ) {
3838
3939 Scanner scanner = new Scanner (System .in );
4040 System .out .println ("Enter a number" );
4141 int n = scanner .nextInt ();
4242 int flag = 0 ;
4343
4444 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 ++)
4646 if (isPrime (i ))
47- if (isPrime (n - i ))
47+ if (isPrime (n - i ))
4848 {
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 ;
5151 }
5252 }
5353 else
5454 System .out .println ("Wrong Input" );
5555 }
5656
57- }
57+ }
You can’t perform that action at this time.
0 commit comments