Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testprime;
- import javax.swing.*;
- public class TestPrime {
- public static void main(String[] args) {
- int num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number"));
- boolean check = testPrime(num);
- if (check == true)
- System.out.println("The number"+ num +"is a prime number");
- else
- System.out.println("The number"+ num +"is not a prime nummber");
- static boolean testPrime(int n)
- {
- int i = 2;
- boolean isPrime = true;
- while(i <= (int)Math.sqrt(n) && iPrime == false)
- {
- if (n % i ==0)
- isPrime = false;
- i++;
- }
- return isPrime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement