-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnhancedForLoopInArrays.java
More file actions
67 lines (60 loc) · 1.39 KB
/
Copy pathEnhancedForLoopInArrays.java
File metadata and controls
67 lines (60 loc) · 1.39 KB
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
65
66
67
public class EnhancedForLoopInArrays
{
public static void main(String[] args)
{
// 1D Array
System.out.println("********************");
System.out.println("1D ARRAY USING ENHANCED FOR LOOP");
int nums [] = {5,4,7,8};
for(int n:nums)
{
System.out.println(n);
}
// 2 D array
System.out.println("********************");
System.out.println("2D ARRAY USING ENHANCED FOR LOOP");
int nums1 [][] = {
{5,2,3,4,8}, {3,4,5,6,7}, {1,2,3,4,5}
};
for(int a[]:nums1)
{
for(int b:a)
{
System.out.print(b + " ");
}
System.out.println();
}
// JAGGED array
System.out.println("********************");
System.out.println("Jagged ARRAY USING ENHANCED FOR LOOP");
int nums2 [][] = {
{5,2,3,4,8}, {3,4,5,7}, {1,2,3,4,5,9,10},{2}
};
for(int c[]:nums2)
{
for(int d:c)
{
System.out.print(d + " ");
}
System.out.println();
}
}
}
/* Output
1D ARRAY USING ENHANCED FOR LOOP
5
4
7
8
********************
2D ARRAY USING ENHANCED FOR LOOP
5 2 3 4 8
3 4 5 6 7
1 2 3 4 5
********************
Jagged ARRAY USING ENHANCED FOR LOOP
5 2 3 4 8
3 4 5 7
1 2 3 4 5 9 10
2
*/