Java program prime or not a prime number

I need to write a program to:

1. ask the user to enter a positive integer

2. check if the number is a prime number or not. If the number is a prime number, display a message like "59 is a prime number" where 59 is the number user entered. Otherwise, display the message like "57 is not a prime number" where 57 is the number user entered.

3. ask the user if he/she wants to check another number and wait for the user to enter "Y" or "y" as yes, "n" or "N" as no. If yes, repeat the three steps. If no, exit the program. For all other letters, reject ti and ask the user to enter only "y" or "n".

It's been driving me crazy for hours. I don't know where to start at all. Or how to start. I learn better by reading but this is not in the book. I just can't learn when the instructor is giving a lecture. I am in serious need for help on this especially because it is due in a few hours ( it was assigned today in the afternoon and due tonight). It usually takes days for me to solve a problem but since this is due the same day, I am really stressed out. Please help.

Re: Java program prime or not a prime number

Dismantle the problem: for now forget about all that IO hoopla and concentrate on the core: what makes a number a prime number? Wouldn't it be nice to have a boolean method isPrime(int n) that returns true only if n is a prime number. Design an implement that method first:

Code:

`public boolean isPrime(int n) {`

// here goes your code ...

}

kind regards,

Jos

Re: Java program prime or not a prime number

From point 2 I can imagine someone doing this:

Code:

`if(isPrime(num)) {`

System.out.println("like \"59 is a prime number\" where 59 is the number user entered");

} else {

System.out.println("like \"57 is not a prime number\" where 57 is the number user entered.");

}