Advertisement
Shaun_B

Prime number checker in java

Aug 8th, 2012
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2. /**
  3.  * @ Shaun B
  4.  * @ v1.0.0.1
  5.  * @ 2012-08-08
  6.  */
  7. public class primeNumber
  8. {
  9.     private static boolean run = true;
  10.     private static int readNumber = 0;
  11.     public static void main (String args [])
  12.     {
  13.         System.out.println ("Donkeysoft MMXII - this will determine whether or not\n"
  14.                         +"the number you enter is a prime or even number. If you wish\n"
  15.                         +"to leave this program, please type in -1 and press enter\n"
  16.                         +"to exit.\n");
  17.         Scanner keyboardBuffer = new Scanner (System.in);
  18.         while (run)
  19.         {
  20.             System.out.println ("Please enter a whole (integer) number");
  21.             System.out.print ("C:\\>");
  22.             readNumber = keyboardBuffer.nextInt();
  23.             if (readNumber%2 == 0)
  24.             {
  25.                 System.out.println ("The integer that you entered is an even number");
  26.             }
  27.             else
  28.             if ( (readNumber%2 != 0 && readNumber %3 != 0) || readNumber == 3)
  29.             {
  30.                 System.out.println ("The integer that you entered is a prime number");
  31.             }
  32.             else
  33.             {
  34.                 System.out.println ("The number is odd but not prime");
  35.             }
  36.             if (readNumber == -1 )
  37.             {
  38.                 System.out.println("\n\nGood bye, have a nice day :-)");
  39.                 run = false;
  40.             }
  41.         }
  42.         return;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement