mardi 14 mars 2017

(int)Math.random()*10 returns zero

This is very simple thing but still I am not able to figure out why line A produces output 0 and line B produces a random number(zero or non-zero)

public static void main(String [] args) {
    int [] intArr = new int[10];
    for(int i=0; i<intArr.length;i++) {
        intArr[i] = (int)Math.random()*20; //lineA
        System.out.println((int) (Math.random()*20)); //lineB
        System.out.println(intArr[i]);
    }

It could be simple. Feeling lost !




Aucun commentaire:

Enregistrer un commentaire