-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTwoDArrays.java
47 lines (38 loc) Β· 1.29 KB
/
TwoDArrays.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package day5;
import java.util.Arrays;
public class TwoDArrays {
/*
time complexity: O(1)
space complexity: O(1)
*/
public static void main(String[] args) {
int[] array = new int[10];
// defining length of array is necessary
int[][] matrix = new int[5][];
matrix[0] = new int[10];
matrix[1] = new int[2];
matrix[2] = new int[20];
matrix[3] = new int[5];
matrix[4] = new int[7];
// System.out.println(matrix[0].length);
// System.out.println(matrix[1].length);
// System.out.println(matrix[2].length);
// System.out.println(matrix[3].length);
// System.out.println(matrix[4].length);
// System.out.println(matrix.length);
int[][] data = new int[10][3];
// data[0] = new int[45];
// data[0] = null;
// System.out.println(data[0]);
// System.out.println(data[1]);
// System.out.println(data[2]);
// System.out.println(data[3]);
System.out.println(Arrays.deepToString(data));
// data[0] = new int[10];
// data[5] = new int[3];
// System.out.println(Arrays.deepToString(data));
data[0][1] = 100;
System.out.println(data[4][2]);
System.out.println(Arrays.deepToString(data));
}
}