math.random always give 0 result

前端 未结 8 801
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 16:40

I am using Ubuntu 14.04.3 LTS and I am studying Java from the book. I tried to follow one example on the book with Ubuntu Terminal and I\'m using Sublime Text. Here is the code

8条回答
  •  一生所求
    2021-01-29 17:09

    Math.random();
    

    Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.

    This is the problem. You need to then multiply with 10, so you get a number between 0 and 10 and after that you can cast to int.

提交回复
热议问题