-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTut8.java
More file actions
64 lines (61 loc) · 873 Bytes
/
Tut8.java
File metadata and controls
64 lines (61 loc) · 873 Bytes
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
package tutorial;
//loops
public class Tut8 {
public static void main(String[] args) {
// for loops
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
System.out.println("Printing Reverse Number");
// printing reverse nu
for (int i = 5; i > 0; i--) {
System.out.println(i);
}
System.out.println("While Loop");
// while loop
int no = 5;
while (no >= 1) {
if (no == 0)
break;
System.out.println(no);
no--;
}
System.out.println("Do while loop");
no = 1;
do {
System.out.println(no);
no++;
} while (no <= 5);
// for each loop
String[] names = { "ab", "cd", "de" };
for (String name : names) {
System.out.println(name);
}
}
}
/*
* Output:
* 0
* 1
* 2
* 3
* 4
* Printing Reverse Number
* 5
* 4
* 3
* 2
* 1
* While Loop
* 5
* 4
* 3
* 2
* 1
* Do while loop
* 1
* 2
* 3
* 4
* 5
*/