-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopsinArray.java
More file actions
53 lines (38 loc) · 1.54 KB
/
Copy pathloopsinArray.java
File metadata and controls
53 lines (38 loc) · 1.54 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
public class loopsinArray {
public static void main(String[] args) {
String[] aplhabets = { "a", "b", "c", "d", "e",
"f", "g", "h", "i", "j" };
int[] num = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// for-each loop
for (String i : aplhabets) {
System.out.println(i);
}
System.out.println("\n******************\n");
for (int i : num) {
System.out.println(i);
}
System.out.println("\n******************\n");
// for loop
for (int i = 0; i < aplhabets.length; i++) {
System.out.print(aplhabets[i]);
System.out.print(num[i] + " ");
}
System.out.println("\n******************\n");
// while loop
int i = 0;
while (i < aplhabets.length) {
System.out.print(aplhabets[i]);
System.out.print(num[i] + " ");
i++;
}
System.out.println("\n******************\n");
// Do-while loop
int j = 0;
do {
System.out.print(aplhabets[j]);
System.out.print(num[j] + " ");
j++;
} while (j < aplhabets.length);
System.out.println("\n******************\n");
}
}