/** * @(#)PrimeNumberCheck.java * * PrimeNumberCheck application * * @author Eric Carr * @version 0.8a 2008/3/27 */ import javax.swing.JOptionPane; public class PrimeNumberCheck { public static String userQuestion; public static int userNumber = 0; public static void main(String[] args) { System.out.println("This Program checks whether a number is prime.\nPlease input your number."); userQuestion = JOptionPane.showInputDialog(null, "Enter your number so it's primality may be checked."); try { userNumber = Integer.parseInt(userQuestion); } catch (NumberFormatException userGivenNumberPrimeCheckNumFormatEx) { System.err.println("You did not enter a number, you entered" + userQuestion + "."); throw userGivenNumberPrimeCheckNumFormatEx; } if (userNumber != 0) { if (primeChecker.isPrime(userNumber) == true) { System.out.println(userNumber + " is prime."); } else { System.out.println(userNumber + " is not prime."); } } } } //External Class primeChecker public class primeChecker { public static boolean isPrime(int x) { int a = 3; //Used to check whether number is prime if ((((Math.pow(a, x))-a)/x) == Math.round(((Math.pow(a, x))-a)/x)) { return true; } else { return false; } } }