hello,I am reading article in this link: https://www.codecademy.com/courses/learn-java/articles/static-methods-of-the-math-class
I found that there might be mistakes in this statement.
int c = (int)(Math.random() * 10) + 1;
Note how the
+ 1
is added outside the parentheses. This is an important syntax to remember. If we placed the+ 1
inside the parentheses, we would get a randomint
between0
and10
My perspective is that even you put+1 inside the parentheses, you will still get from 1 to 10.
the minimum math.random() generate is very close to zero, if you add one to it, it will be one point something, then you cast to int , it will be one. So it is a number between 1 and 10 not a number between 0 and 10.