0

Need help with my java program, I know how to use the random class to generate a random number up to a certain number; but for this specific program I need to generate a random number out of 0 ,10 ,20 ,30 ,40 , and 50.

user9133
  • 17
  • 2
  • 3
    probably a homework assignment, so think about how you could get a random range and then do some math to the result of it, which will get you what you need. – edthethird Oct 23 '17 at 17:30

2 Answers2

5

Generate a number in the range of [0, 5], then multiply it by 10.

Tim
  • 810
  • 9
  • 20
1

First generate a randomNumber in the range 0-5 and then multiply it times 10

Random random = new Random();
int randomNum = 10 * random.nextInt(6);
inxoy
  • 3,484
  • 2
  • 13
  • 21