Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean isPrime(long number)
- {
- if (number % 2 == 0)
- {
- JOptionPane.showMessageDialog(null, "It is not a prime");
- return false;
- }
- else
- {
- long end = (long) Math.sqrt(number) + 1;
- for (long divisor = 3; divisor <= end; divisor+=2)
- {
- if (number % divisor == 0)
- {
- JOptionPane.showMessageDialog(null, "It is not a prime");
- return false;
- }
- }
- JOptionPane.showMessageDialog(null, "It is a prime");
- return true;
- }
- }
- public void primesToANumber() //finds all primes
- {
- }
- }
- public class runner
- {
- public static void main(String[] args)
- {
- Primes primechecker = new Primes ();
- Primes primesToANumber = new Primes ();
- boolean done = false;
- while (done == false)
- {
- String[] choices = {"Choose 1 if you want to test if a number is prime or not",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7"};
- String s = (String)JOptionPane.showInputDialog(
- null,
- "PLease choose an option", //the question
- "Your Choice", //the frame title
- JOptionPane.PLAIN_MESSAGE, //the icon type
- null, //an icon you select
- choices, //array of options
- choices[0]); //the default to be selected
- if(s.equals(choices[0]))
- {
- String numberString = JOptionPane.showInputDialog("Enter any integer");
- long number = Long.parseLong(numberString);
- primechecker.isPrime(number);
- }
- else if(s.equals(choices[1]))
- {
- String numberString1 = JOptionPane.showInputDialog("Enter any integer");
- long num = Long.parseLong(numberString1);
- primesToANumber.primesToANumber(num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement