Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+15 votes

How can you print random numbers using rand.nextInt(); when the range is not starting at 0?

asked in CSC211_Winter2018 by (1 point)

1 Answer

+11 votes

To print random number, you need to attach it to a variable. For example, int num=rand.nextInt();. Then, print that variable like normal. For a fixed range, if you want to start the range not starting at 0, you will add a start number (min). The range will go from min to max. For example, int num=rand.nextInt(max - min + 1) + min; int num=rand.nextInt(9) + 3; this range will goes from 3 to 11.

answered by (1 point)
...