Generating a Random Number between 1 and 10 Java [duplicate]

I want to generate a number between 1 and 10 in Java.

Here is what I tried:

Random rn = new Random();
int answer = rn.nextInt(10) + 1;

Is there a way to tell what to put in the parenthesis () when calling the nextInt method and what to add?

3 Answers
3

Leave a Comment