forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoops7A.java
More file actions
73 lines (66 loc) · 1.4 KB
/
Loops7A.java
File metadata and controls
73 lines (66 loc) · 1.4 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
68
69
70
71
72
73
public class Loops7A
{
public static void main(String[] args)
{
System.out.println("For Loop Up:");
forLoopUp();
System.out.println("For Loop Down:");
forLoopDown();
System.out.println("While Loop Up:");
whileLoopUp();
System.out.println("While Loop Down:");
whileLoopDown();
System.out.println("Do While UP:");
doWhileLoopUp();
System.out.println("Do While Down:");
doWhileLoopDown();
}
private static void forLoopUp()
{
for(int i = 1;i < 11; i++)
System.out.println(i);
}
private static void forLoopDown()
{
for(int i = 10; i > 0; i--)
{
System.out.println(i);
}
}
private static void whileLoopUp()
{
int i = 1;
while(i < 11)
{
System.out.println(i);
i++;
}
}
private static void whileLoopDown()
{
int i = 10;
while(i > 0)
{
System.out.println(i);
i--;
}
}
private static void doWhileLoopUp()
{
int i = 1;
do
{
System.out.println(i);
i++;
}while(i < 11);
}
private static void doWhileLoopDown()
{
int i = 10;
do
{
System.out.println(i);
i--;
}while(i > 0);
}
}