shivamisone

goldbach

Oct 4th, 2023
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * goldback
  5.  */
  6. public class goldback {
  7.  
  8.     public static void main(String[] args) {
  9.         int l = 0;
  10.         Scanner sc = new Scanner(System.in);
  11.         System.out.println("enter a number");
  12.         int s = sc.nextInt();
  13.         if (s % 2 != 0) {
  14.             System.out.println("invalid input odd number");
  15.             System.exit(0);
  16.         }
  17.         int[] ar = new int[s];
  18.         for (int i = 2; i < s; i++) {
  19.             if (lla(i)) {
  20.                 ar[l] = i;
  21.                 l++;
  22.             }
  23.  
  24.         }
  25.         for (int i = 0; i < ar.length; i++) {
  26.             int k = ar[i];
  27.             for (int j = 0; j < ar.length; j++) {
  28.                 if (k + ar[j] == s) {
  29.                     System.out.println(k + "   " + ar[j]);
  30.                     ar[i] = 0;
  31.                 }
  32.             }
  33.         }
  34.         sc.close();
  35.     }
  36.  
  37.     public static boolean lla(int i) {
  38.         int count = 0;
  39.         for (int j = 2; j < i; j++) {
  40.             if (i % j == 0) {
  41.                 count++;
  42.             }
  43.         }
  44.         if (count == 0) {
  45.             return true;
  46.         } else
  47.             return false;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment