lundi 11 janvier 2016

Java random number

Beginner question here: I tried creating a random number using this code

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

however, i kept receiving 0 as the answer when printing to screen

only after putting parenthesis like so

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

did the number show properly. Can anyone explain the logical reason for this that I missed?




Aucun commentaire:

Enregistrer un commentaire