-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhileLoop.java
43 lines (39 loc) · 1008 Bytes
/
WhileLoop.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
class WhileLoop{
public static void main(String[] args) {
int i=0;
/*while (condition) {
code block to be executed
}
*/
while(i<5){
System.out.println("Printing while loop");
i++;
}
/*do {
code block to be executed
}while (condition);
*/
int j=0;
do{
System.out.println("Printing do while loop");
j++;
}while(j<5);
//real life example
int count=3;
while(count>0){
System.out.println(count);
count--;
}
System.out.println("Happy new year");
//Print "Yatzy!" If the dice number is 6
int dice = 1;
while (dice <= 6) {
if (dice < 6) {
System.out.println("No Yatzy.");
} else {
System.out.println("Yatzy!");
}
dice = dice + 1;
}
}
}