How to get a random between 1 - 100 from randDouble in Java?

后端 未结 6 533
滥情空心
滥情空心 2020-12-11 01:55

Okay, I\'m still fairly new to Java. We\'ve been given an assisgnment to create a game where you have to guess a random integer that the computer had generated. The problem

6条回答
  •  醉梦人生
    2020-12-11 02:37

    You're almost there. Just add 1 to the result:

    int randomInt = (int)d + 1;
    

    This will "shift" your range to 1 - 100 instead of 0 - 99.

提交回复
热议问题