-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhileAndDoWhile.java
45 lines (40 loc) · 992 Bytes
/
WhileAndDoWhile.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
package Chapter2.src;
public class WhileAndDoWhile {
public static void main(String[] args) {
/*
* int x = 0;
* while (x != 10) {
* System.out.println(x);
* x++;
* }
*
* do {
* System.out.println("Count value was " + x);
* x++;
* } while (x != 6);
* }
*/
int x = 4;
int lastNum = 20;
int count = 0;
while (x <= lastNum) {
x++;
if (!isEvenNumber(x)) {
continue;
}
System.out.println("Even number " + x);
count++;
if (count >= 5) {
break;
}
}
System.out.println("even number total " + count);
}
public static boolean isEvenNumber(int x) {
if (x % 2 == 0) {
return true;
} else {
return false;
}
}
}