-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07JavaLooping.java
More file actions
53 lines (42 loc) · 1.15 KB
/
07JavaLooping.java
File metadata and controls
53 lines (42 loc) · 1.15 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
class JavaLooping {
public static void main(String[] args) {
// for loops : program to print all even numbers between 0-50
for (int i = 0; i <= 50; i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
// while loop :
int num = 0;
while (num <= 5) {
System.out.println("Hello World !");
num++;
}
// do-while loop:
do {
System.out.println("Hello from do-while loop");
num++;
} while (num > 10);
// Nested loop:
// outer loop
for (int i = 1; i < 5; i++) {
// inner loop
for (int j = 0; j <= i; j++) {
System.out.print(i + "," + j + " ");
}
System.out.println();
}
int weeks = 3;
int days = 7;
int i = 1;
// outer loop
while (i <= weeks) {
System.out.println("Week: " + i);
// inner loop
for (int j = 1; j <= days; ++j) {
System.out.println(" Days: " + j);
}
++i;
}
}
}