-
What would be the output of following code snippet?
int ran = random.nextInt(10) + 2;
-
- Random number between 4 to 10, excluding 4 and 10
- Random number between 2 to 11, including 2 and 11
- Random number between 2 to 11, excluding 2 and 11
- Random number between 2 to 10, including 2 and 10
- None of these
Correct Option: B
random.nextInd(10) + 2; returns random numbers between 2 to 11 including 2 and 11. it follows “nextInt(max – min +1) + min” formula.