posted 1 year ago

Were you told to use

Adding and multiplying how? Do you mean the sum and product of your three numbers? If so, read Les's post.

Winston

Isaac Ade wrote:I have been assigned a piece of homework where I am required to print three random numbers, add them then multiply them.

Were you told to use

`Math.random()`? Because there's a much simpler way to get a random

`int`. Have a look at

`java.util.Random`(←click).

I have already printed the random numbers and I require help with adding and multiplying

Adding and multiplying how? Do you mean the sum and product of your three numbers? If so, read Les's post.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

posted 1 year ago

I was told to use Math.random() and thank you.

Winston Gutkowski wrote:Isaac Ade wrote:I have been assigned a piece of homework where I am required to print three random numbers, add them then multiply them.

Were you told to useMath.random()? Because there's a much simpler way to get a randomint. Have a look atjava.util.Random(←click).

I have already printed the random numbers and I require help with adding and multiplying

Adding and multiplying how? Do you mean the sum and product of your three numbers? If so, read Les's post.

Winston

I was told to use Math.random() and thank you.

Isaac

posted 1 year ago

Thank you Les I'm going to test this now.

Les Morgan wrote:Isaac,

Any time you want to work with the same number in multiple operations, you need to capture the number--save them in variables so you can use them.

Les

Thank you Les I'm going to test this now.

Isaac

posted 1 year ago

There's no '

HIH

Winston

Isaac Ade wrote:Would you be able to give me an example on how to use the --save command

There's no '

`save`' command; it's just an assignment or a modification, viz:

`int sum = 0;`

...

sum = sum + iRandNum;

...

sum = sum + iRandNum;

HIH

Winston

Articles by Winston can be found here

Campbell Ritchie

Marshal

Posts: 55677

161

posted 1 year ago

Back to random numbers. Never mind what the Java™ Tutorials (scroll to bottom of page) says, I still think it is usually better not to us Math#ranom. One of the things about having been ere for a long time (ten years in my case) is that you can remember old discussions, like this thread about different ways to ge “random” numbers.

And welcome to the Ranch

And welcome to the Ranch

posted 1 year ago

Thanks Campbell

Campbell Ritchie wrote:Back to random numbers. Never mind what the Java™ Tutorials (scroll to bottom of page) says, I still think it is usually better not to us Math#ranom. One of the things about having been ere for a long time (ten years in my case) is that you can remember old discussions, like this thread about different ways to ge “random” numbers.

And welcome to the Ranch

Thanks Campbell

Isaac