Java Array multidimensional Arrays initialize arrays with random values

Description

Java Array multidimensional Arrays initialize arrays with random values

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    int[][] matrix = { { 1, 2 }, { 3, 4 }, { 5, 6 } };

    System.out.println(Arrays.deepToString(matrix));
    for (int row = 0; row < matrix.length; row++) {
      for (int column = 0; column < matrix[row].length; column++) {
        matrix[row][column] = (int) (Math.random() * 100);
      }/*from  w  ww  .  j  av  a  2s  .c  om*/
    }

    System.out.println(Arrays.deepToString(matrix));
  }
}



PreviousNext

Related