lundi 16 octobre 2017

Why does [ (int) (Math.random() * 10);] Produce 0 When the Parentheses Are Absent? [duplicate]

This question already has an answer here:

I have a question regarding the random() method in the Java Math class.

If I were to generate a random number and cast it into an integer type between 0 and 9, then I would write:

int x = (int) (Math.random() * 10);;

However, I've noticed that if I write:

int x = (int) Math.random() * 10);;

without the parentheses around Math.random(), the output is always 0. Why is that?

Thank you.




Aucun commentaire:

Enregistrer un commentaire