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
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 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
I was told to use Math.random() and thank you.
Isaac
Les Morgan wrote:Isaac,
Any time you want to work with the same number in multiple operations, you need to capture the numbersave them in variables so you can use them.
Les
Thank you Les I'm going to test this now.
Isaac
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;
HIH
Winston
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
And welcome to the Ranch
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
I can't take it! You are too smart for me! Here is the tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
