Random boolean 2d-array in Java returning always "false" -
i wanted create random boolean 2d-array returns false...a problem operator "&&"? don't it...
public static void main(string[] args){ boolean[][] arr = new boolean[5][5]; random r = new random(); boolean row = r.nextboolean(); boolean col = r.nextboolean(); for(int i=0 ; i<arr.length ; i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j] = row && col; system.out.print(arr[i][j]+"\t"); } }
i think want create new random boolean each cell in array this:
public static void main(string[] args){ boolean[][] arr = new boolean[5][5]; random r = new random(); for(int = 0; < arr.length; i++){ for(int j = 0; j < arr[i].length; j++){ arr[i][j] = r.nextboolean(); system.out.print(arr[i][j]+"\t"); } } }
Comments
Post a Comment