matrix java code example

Example 1: java two dimensional arrays

int[][] multiples = new int[4][2];     // 2D integer array with 4 rows 
                                          and 2 columns
String[][] cities = new String[3][3];  // 2D String array with 3 rows 
                                          and 3 columns

Example 2: 2d array java

char[][] array = new int[rows][columns];

Example 3: declare matrix in java

int[][] multi = new int[5][];
multi[0] = new int[10];
multi[1] = new int[10];
multi[2] = new int[10];
multi[3] = new int[10];
multi[4] = new int[10];

Example 4: java matrix

int [ ] [ ] scores = {   { 20, 18, 22, 20, 16 },
                                 { 18, 20, 18, 21, 20 },
                                 { 16, 18, 16, 20, 24 },
                                 {  25, 24, 22, 24, 25 }
                             };