Home » JAVA Programming » Numbers » Question
  1. What would be the output of following code snippet?
    int ran = random.nextInt(10) + 2;
    1. Random number between 4 to 10, excluding 4 and 10
    2. Random number between 2 to 11, including 2 and 11
    3. Random number between 2 to 11, excluding 2 and 11
    4. Random number between 2 to 10, including 2 and 10
    5. 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.



Your comments will be displayed only after manual approval.