Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (a1234):

Java parameters question...

OpenStudy (a1234):

OpenStudy (a1234):

This is what I have so far: public int rollDice(int sides) { int x = sides; double randomNumber=Math.random(); randomNumber=randomNumber*x; randomNumber=randomNumber+1; int randomInt=(int)randomNumber; return randomInt; }

OpenStudy (woodrow73):

try running your program a few times with different values passed to the method, see if the output is what you expect.

rvc (rvc):

Seems perfect. Try more no of test cases.

OpenStudy (rsmith6559):

FYI, your variable x isn't needed. You can freely use sides. Primitive data types ( int, bool, float, double ) are copied into a function/method. So sides is a copy only in the scope of your function/method.

OpenStudy (a1234):

Thank you everyone!

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!
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!