i'm trying generate multi-dimensional array works upon random integers generated. i'm unable because doesn't work properly.
public class gen(){ public static void main(string[] args){ int randomrow, randomcol; int[][] array1 = new int[61][50]; for(int row = 0; row < array1.length; row++){ for(int col = 0; col < array1.length; col++){ randomrow = 1 + (int)(math.random() * 100); randomcol = 1 + (int)(math.random() * 100); array1[row][col] = array1[randomrow][randomcol]; system.out.println(array1[row][col] + "/n"); } } } }
but not work. reason why?
i think trying put random numbers between 0 , 99 in array. correct? if so:
random random = new random(); (int = 0; < array.length; i++) (int j = 0; j < array[i].length; j++) array[i][j] = 1 + random.nextint(100);
note if using java 8 there simpler technique generate array of random integers assigning random value each position:
array[] = random.ints(60, 1, 101).toarray();
Comments
Post a Comment