forked from kunalbandale/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayCreation.java
42 lines (31 loc) · 967 Bytes
/
ArrayCreation.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
public class ArrayCreation {
public static void main(String[] args) {
int num[] = {4,5,6};
num[1] = 10;
System.out.println(num[1]);
// dynamic array
int nums[] = new int[4];
nums[0] = 12;
nums[1] = 2;
nums[2] = 1;
nums[3] = 34;
// printing values
for (int i = 0; i <= 3 ; i++) {
System.out.println(nums[i]);
}
// 2-D array
int numbers[][] = new int[3][4];
for (int i = 0 ; i < 3 ; i ++) {
for (int j = 0 ; j<4 ; j ++) {
numbers[i][j] = (int) (Math.random() * 100);
System.out.println(numbers[i][j]);
}
}
for (int i = 0 ; i < 3 ; i ++) {
for (int j = 0 ; j<4 ; j ++) {
System.out.print(numbers[i][j] + " ");
}
System.out.println();
}
}
}