-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_15_while_challenge.java
More file actions
43 lines (35 loc) · 1.22 KB
/
Copy pathDay_15_while_challenge.java
File metadata and controls
43 lines (35 loc) · 1.22 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
package Programing.Section5;
// Create a method called isEvenNumber that takes a parameter of type int
// Its purpose is to determine if the argument passed to the method is
// an even number or not.
// return true if an even number, otherwise return false;
// also Make it also record the total number of even numbers it has found
// and break once 5 are found
// and at the end, display the total number of even numbers found
public class Day_15_while_challenge {
public static void main(String[] args) {
int number = 5;
int finishNumber = 20;
int evenNumbersFound = 0;
while (number <= finishNumber) {
if (!isEvenNumber(number)) {
number++;
continue;
}
System.out.println("Even number " + number);
number++;
evenNumbersFound++;
if (evenNumbersFound >= 5) {
break;
}
}
System.out.println("Total even numbers found = " + evenNumbersFound);
}
public static boolean isEvenNumber(int number) {
if((number % 2) == 0) {
return true;
} else {
return false;
}
}
}