chillurbrain

Task5Lab5_1

Dec 9th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Task5_5_1 {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         int check_value = sc.nextInt();
  7.         int i;
  8.         if((check_value % 2) != 0) {
  9.             System.out.println("Invalid input");
  10.         }
  11.         else{
  12.             for (i = 3; i <= (check_value / 2); i += 2) {
  13.                 if (isPrime(i) && isPrime(check_value-i)) {
  14.                     System.out.println(i + " "+(check_value-i));
  15.                 }
  16.             }
  17.         }
  18.     }
  19.    
  20.     public static boolean isPrime(int n) {
  21.         if ((n % 2) == 0) {
  22.             return false;
  23.         }
  24.         for (int i = 3; i < Math.sqrt(n); i += 2) {
  25.             if ((n % i) == 0) {
  26.                 return false;
  27.             }
  28.         }
  29.         return true;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment