Hey man,
I know I'm going to get thrashed for this... but it happens. Here is my code written in
JAVA for the same exact problem. I have it done in JAVA and the theory is the same, all you have to do is change the syntax. So here it is:
CODE
for (int i = 2; i <= (Math.sqrt(primeInput)); i++)
{
if ((primeInput % i) == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
JOptionPane.showMessageDialog(null, "The number you entered " + primeInput + " is PRIME!!", "We have found a prime!", JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "The number you entered " + primeInput + " is NOT PRIME!!", "We have FAILED!", JOptionPane.ERROR_MESSAGE);
Also, I forgot about your non-negative number input, once again here is my code in
JAVA.
CODE
while (primeInput < 0)
{
JOptionPane.showMessageDialog(null,"That was not a positive integer!", "That was not a positive integer!", JOptionPane.ERROR_MESSAGE);
inputStr = JOptionPane.showInputDialog("Please input a positive integer: ");
primeInput = Integer.parseInt(inputStr);
}
This post has been edited by mikepetro: 18 Nov, 2005 - 11:32 PM