prime number problem
Hi, I am new to java and and I am trying to figure out what my problem is with this prime number program. I have looked through other posts, but I was wondering if someone could look over my specific code and give me some direction. I think I am close, but not sure how to get around my problem. I know I should use a boolean, but I am not sure why this isn't working. Right now, if I enter '4' for instance, the message says it is a prime number. Any help?
Thanks.
here is the code I have so far:
public static void main(String[] args) {
int entry = Integer.parseInt(JOptionPane.showInputDialog("Please enter a number greater than 1:"));
boolean isPrime = true;
if (entry == 0){
System.exit(0);
}
for (int i = entry - 1; i > 1; i--){
int mod = entry%i;
if(mod == 0){
//JOptionPane.showMessageDialog(null, "The number " + entry + " is composite.");
isPrime = false;
break;
}
if (isPrime == true)
JOptionPane.showMessageDialog(null, "The number " + entry + " is prime.");
if (isPrime == false)
JOptionPane.showMessageDialog(null, "The number " + entry + " is composite.");
}
}
}

