Justin Fox

Ranch Hand

Posts: 802

Robert Hill

Ranch Hand

Posts: 94

posted 11 years ago

you can't do directly from what is available in the API, but with a little thought and arithmetic you might come up with a way to do this. I am curious what problem solving steps you attempted, since this is an easy problem. Problem solving is very important, the API can't do all your thinking for you.

If all you needed to do was get a number between 40 and 240 that is easily accomplished with the nextInt(int n) method and simple addition.

What you need is actually simpler. If you multiply 2*20 you get 40, if you multiply 12*20 you get 240. Since you are multiplying by 20, they are obviously multiples of 20. So now you know the range of the random numbers, and the multiple. Should be a piece of cake.

Sorry for basically giving you the solution. It is hard to give hints for these simple problems without solving it.

[ September 30, 2006: Message edited by: Robert Hill ]

If all you needed to do was get a number between 40 and 240 that is easily accomplished with the nextInt(int n) method and simple addition.

What you need is actually simpler. If you multiply 2*20 you get 40, if you multiply 12*20 you get 240. Since you are multiplying by 20, they are obviously multiples of 20. So now you know the range of the random numbers, and the multiple. Should be a piece of cake.

Sorry for basically giving you the solution. It is hard to give hints for these simple problems without solving it.

[ September 30, 2006: Message edited by: Robert Hill ]