-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.java
67 lines (53 loc) · 1.46 KB
/
array.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// array - arrays are used to store more than one values of same data type.
class Main
{
public static void main(String a[])
{
int arr[] = {1,2,3};
int num[] = new int[4]; // to declare a new array with the size
arr[1] = 0; // assigning new value to the arr
System.out.println(arr[0]); // To retrieve a particular element from the array.
System.out.println(num);
}
}
// Multi dimensional array
class Method {
public static void main(String a[]) {
int arr[][] = new int[3][4];
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 4; j++)
{
System.out.println(arr[i][j]);
}
}
}
}
// enhance for loop
class Method {
public static void main(String a[]) {
int arr[][] = new int[3][4];
for (int n[] : arr){
for (int m: n){
System.out.println(m + " ");
}
System.out.println();
}
}
}
// Jagged Arrays - when the size of the array is varied.
class Method {
public static void main(String a[]) {
int arr[][] = new int[3][];
arr[0] = new int[2];
arr[1] = new int[3];
arr[2] = new int[4];
for(int i = 0; i < arr.length; i++)
{
for(int j = 0; j < arr[i].length; j++)
{
System.out.println(arr[i][j]);
}
}
}
}