Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * @ Shaun B
- * @ v1.0.0.1
- * @ 2012-08-08
- */
- public class primeNumber
- {
- private static boolean run = true;
- private static int readNumber = 0;
- public static void main (String args [])
- {
- System.out.println ("Donkeysoft MMXII - this will determine whether or not\n"
- +"the number you enter is a prime or even number. If you wish\n"
- +"to leave this program, please type in -1 and press enter\n"
- +"to exit.\n");
- Scanner keyboardBuffer = new Scanner (System.in);
- while (run)
- {
- System.out.println ("Please enter a whole (integer) number");
- System.out.print ("C:\\>");
- readNumber = keyboardBuffer.nextInt();
- if (readNumber%2 == 0)
- {
- System.out.println ("The integer that you entered is an even number");
- }
- else
- if ( (readNumber%2 != 0 && readNumber %3 != 0) || readNumber == 3)
- {
- System.out.println ("The integer that you entered is a prime number");
- }
- else
- {
- System.out.println ("The number is odd but not prime");
- }
- if (readNumber == -1 )
- {
- System.out.println("\n\nGood bye, have a nice day :-)");
- run = false;
- }
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement