-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountingWhile.java
121 lines (108 loc) · 2.58 KB
/
CountingWhile.java
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.Scanner;
public class CountingWhile {
public static void main(String[]args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println( "Type in a message, and I'll display it five times.");
System.out.print( "Message: ");
String message = keyboard.nextLine();
System.out.println("How many times?(1 to 10)");
int num = keyboard.nextInt();
if(num == 1)
{
int n = 0;
while( n < 10)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 2)
{
int n = 0;
while( n < 20)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 3)
{
int n = 0;
while( n < 30)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 4)
{
int n = 0;
while( n < 40)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 5)
{
int n = 0;
while( n < 50)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 6)
{
int n = 0;
while( n < 60)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 7)
{
int n = 0;
while( n < 70)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 8)
{
int n = 0;
while( n < 80)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 9)
{
int n = 0;
while( n < 90)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else if(num == 10)
{
int n = 0;
while( n < 100)
{
System.out.println( (n+10) + ". " + message);
n+=10;
}
}
else
{
System.out.println(" ");
}
/*n++ in the while loop increments the counter(n) by
1 whenever something happens and without it the loop runs without exiting*/
}
}