Ask your own question, for FREE!
Computer Science 43 Online
OpenStudy (anonymous):

In PS2 I'm having problem with test method for primes... How to solve that?

OpenStudy (anonymous):

I'm not sure what class you are taking, but I would imagine from a pseudocode perspective the best approach to finding out if a number is a prime is to use an incremental loop which divide the number by the loop counter and sees if there is a remainder. If there is no remainder then the number is not a prime. You will ant to skip the number 1 and the number itself so the loop will go from 2 to n-1. prime = true; for (i=2; i < (n-1); i++) { if ((n % i)=0) { prime = false; } } Nothing fancy but a basic Java loop to address the question.

OpenStudy (rsmith6559):

Post your code, ask a specific question and we'll have something to help you with. Otherwise, the answer to your question is: consider the attributes that make a number prime, and develop tests for each of those characteristics.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Twaylor: It's my birthday :D
1 hour ago 0 Replies 0 Medals
breiadabrattz: I thought C on this..
17 hours ago 39 Replies 2 Medals
breiadabrattz: I really don't understand this .
17 hours ago 14 Replies 0 Medals
gelphielvr: How can I better memorize phrases in a different language?
11 hours ago 5 Replies 0 Medals
Breathless: Breathless Gang (join the cult)
19 hours ago 1 Reply 0 Medals
gelphielvr: What are some interesting careers in nanotechnology?
22 hours ago 2 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!