Program Two
Program Two
1. START!
19. END!
Source Code
import java.util.*; //importing utility packages
public class ProgramTwo { //start of class
public static void main(String[] args) { //start of main
Scanner sc = new Scanner (System.in);
System.out.print("Input: N=");
int N = sc.nextInt();
ProgramTwo ob = new ProgramTwo();
if(N%2==0)
{ //check if the number is even
if(N>9 && N<50)
{ //checking if its within range
System.out.println("Output: Prime Pairs are:");
for(int i=3; i<=N; i++)
{ //finding all prime pairs
if(ob.prime(i))
{
if(ob.prime(N-i))
{
System.out.println("\t" + i + "," + (N-i));
}
}
}
}
else
{
System.out.println("Output: Invalid Input, Number out of range");
System.exit(0);
}
}
else System.out.println("Output: Invalid Input, Number is Odd");
} //end of main
boolean prime(int x)
{ //start of function to check if the number is prime
int c=0;
for(int i=1; i<=x; i++)
{
if(x%i==0)c++;
}
if(c==2) return true;
else return false;
} //end of function
} //end of class
Output