This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have to write a java program that takes a positive number entered by the user and displays whether or not it is prime. The assignment states that an even number is prime if it is 2, and an odd number is prime if it isn't divisible by any integer between 2 and the square root of the number. I really hadn't the faintest clue where to start, but I took a stab at it. Here is the program that I came up with... Any help would be greatly appreciated as I haven't the faintest clue how to do this and the assignment is due tomorrow..
[ November 02, 2003: Message edited by: Brandi Love ]
First, I don't think you want the prompt for the user to be inside the loop. It gets in the way of trying to figure out if you have a prime. Next you are incrementing "count" in two places. You are going to confuse your self doing that. You didn't add the quick and easy check for the user entering "2". Don't worry about trying to loop to ask the user for another number. Get the program to work for the user entering one number. Than you will find it is easy to put all into a loop. You are off to a good start. Add some print statements so that you can see what is happening and start testing with easy ones.
Please ignore post, I have no idea what I am talking about.