i was trying to use JOptionPane as the input mode to find out if the input number is prime or not.. but i am stuck with this code..
Code:
package primeNo;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class primeNo {
public static void main(String[] args) {
int num;
JOptionPane.showInputDialog("Please enter a number : ");
Scanner user_num1=new Scanner(System.in);
int i;
for (i=2; i<num; i++){
int n=num%i; //this is where it all went wrong
if (n==0) {
JOptionPane.showMessageDialog(null,"This is not a prime no.");
break;
}
}
if (i==num) {
JOptionPane.showMessageDialog(null,"This is a prime no.");
}
}
}
Comment