# Two conditions in a while statement

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 08-22-2013, 03:31 PM
SurfMan
Re: Two conditions in a while statement
Quote:

Originally Posted by loki88
Eureka! I've found the solution.

For some reason, I had to change my sum and product variables also in calculations. For a strange reason, at the end they are just zero. How comes that?

Look at the place where you calculate the sum and product. Is that inside the loop? What values are number1 and number2. Do these change at the time of calculation?
• 08-22-2013, 03:55 PM
loki88
Re: Two conditions in a while statement
Oh, I thought if I did
Code:

` int sum = number1 + number2;`
java would always use the current value of that number, thats why I use variables instead of plain numbers right?
If I put the same line of code in the loop the value gets printed right. Thanks for pointing out the error.
• 08-22-2013, 04:03 PM
SurfMan
Re: Two conditions in a while statement
When you type
Code:

`int sum = number1 + number2;`
, you tell your program to caculate this. Nothing automatic, nothing fancy, just a one shot calculation. The reason you use variables in this case is to prevent typing in the same value in multiple different places.
• 08-22-2013, 04:05 PM
gimbal2
Re: Two conditions in a while statement
Quote:

Originally Posted by JosAH
Why doesn't anyone apply a bit of math 101 anymore?

I can't speak for the rest of the world, but speaking out of experience in the NL: math schooling nowadays sucks balls and is being phased out more and more. Only in the very beginning of my education did (basic) math really matter; even I, still quite young but not in my twenties anymore, have never been properly trained to apply math in the real world; I was only taught how to do some calculations which I quickly forgot again because I really don't need that on a daily basis.

The only math that really stuck with me was self-taught; for game-development purposes. Because at least that is math I have learned to apply.
• 08-22-2013, 04:14 PM
loki88
Re: Two conditions in a while statement
I follow gimbal2. I live in Belgium, very close to the Netherlands.

I had basic math in highschool. After that, I got an university degree in criminology. I only needed statistics.
Don't ask me anything on the math I have seen in high school. I simply didn't use it for years and I forgot everything.
• 08-22-2013, 04:27 PM
JosAH
Re: Two conditions in a while statement
So far for the 'knowledge economy' in Belgium and the Netherlands. All 'hard' sciences are based on at least a bit of math and imho computer science is no exception. In this forum (and others) problems are 'solved' where a bit of math could've given a smarter, shorter, faster solution, but indeed, math is not en vogue anymore ...

kind regards,

Jos
• 08-22-2013, 05:19 PM
jim829
Re: Two conditions in a while statement
Or just use the appropriate quadratic formula algorithm. Thought of that but I figured the OP wanted to play around with loops and random numbers.

Regards,
Jim
• 08-22-2013, 05:23 PM
jim829
Re: Two conditions in a while statement
Quote:

Originally Posted by loki88
@Jim29

I tried to group the two conditions (sum and product in one boolean operator, but I get the error I can't use && with an INT variable)

My earlier post said the following:
"... a thru d are either boolean values or logical expressions"

An int value is not a boolean value or logical expression.

Regards,
Jim
• 08-22-2013, 06:08 PM
JosAH
Re: Two conditions in a while statement
Quote:

Originally Posted by jim829
Or just use the appropriate quadratic formula algorithm.

Erm, 'completing squares' is equivalent to the 'appropriate quadratic formula' only simpler to do by the wetware between your ears ;-)

kind regards,

Jos
• 08-22-2013, 06:21 PM
KevinWorkman
Re: Two conditions in a while statement
Quote:

Originally Posted by JosAH
Erm, 'completing squares' is equivalent to the 'appropriate quadratic formula' only simpler to do by the wetware between your ears ;-)

kind regards,

Jos

He's a mathematician! Burn him!
• 08-22-2013, 06:26 PM
jim829
Re: Two conditions in a while statement
I guess I didn't explain myself clearly. By appropriate I meant appropriate for floating point calculations.

Quadratic equation - Wikipedia, the free encyclopedia

Regards,
Jim

• 08-22-2013, 06:37 PM
JosAH
Re: Two conditions in a while statement
Quote:

Originally Posted by KevinWorkman

I'm not a mathematician, you dressed me up like that and put on that nose!

kind regards,

Jos Ni! Ni! Ni! ;-)
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12