What will be the output of the following Java code snippet?

int a = random.nextInt(7) + 4;

a) Random number between 4 to 7, including 4 and 7
b) Random number between 4 to 7, excluding 4 and 7
c) Random number between 4 to 10, excluding 4 and 10
d) Random number between 4 to 10, including 4 and 10

1 thought on “What will be the output of the following Java code snippet?”

  1. d
    Explanation: random.nextInd(7) + 4; returns random numbers between 4 to 10 including 4 and 10. it follows “nextInt(max – min +1) + min” formula.

Leave a Comment