ValeriePurvis, on 13 October 2012 - 11:53 AM, said:
Have a question.... been thinking..... would I want to do an if numStars.equal (-1) to trigger the exit to the loop if that statement were true?
numStars is an int, I think? If so, then it doesn't have methods - it's a primitive. (we'll talk about classes and primitives another time). In that case you'd compare it with == like so
if (numStars == -1) { blah blah }
But yes that would be a good condition to use to exit the loop.
Schematically:
in the loop
{
get input
if the input is the exit value
exit the loop
process the input normally // if we get to here, we haven't exited the loop
}
The other approach is very, very similar. Maybe you can try to sketch it out in the same way. (you can cut and paste - there will be very few changes, and they will be mostly to the comment)
Math is fun. You've just been doing arithmetic, and there's a lot more to math than arithmetic.
For example try to answer this one: is the set of positive integers larger than the set of positive even integers?

New Topic/Question
Reply




MultiQuote







|