Please pick a number between 1-10 and I, the computer, will guess it. Is the num
ID: 3633519 • Letter: P
Question
Please pick a number between 1-10 and I, the computer, will guess it.Is the number 6 ? n
Is my guess larger or smaller than your number ?smaller
Is the number 3 ? n
Is my guess larger or smaller than your number ?larger
the number 5 ? y
I got your number 5 in 3 guess(es)!
explanation to help:. You need to work with random number generation from a given range. In order to generate a random number within the range [min, max] inclusive, we can simply use the Random class as:
Random rand = new Random();
int myRandomNumber = rand.nextInt(max - min + 1) + min;
Here, (max - min + 1) is the size of range.
For example, to generate a random integer number between 22 and 30 inclusive, we write
int myRandomNumber= rand.nextInt(9) + 22;