-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathEvenIntegers.java
34 lines (28 loc) · 1.07 KB
/
EvenIntegers.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
public class EvenIntegers {
/** This is a method that takes an array of integers and checks the length of the integers and return the integers that are even in length
*
* @param nums which is an array of integers
* @return evenNumber_count
*/
static int checkEvenNumbers(int[] nums) {
int evenNumber_count = 0;
for (int num : nums) {
int length = String.valueOf(num).length();
//Check if the length of of a given integer is divisible by 2,
// increment the count and check for the next integer
if (length % 2 == 0)
evenNumber_count++;
}
//return the integers that are even
return evenNumber_count;
}
/*
* main method
*/
public static void main(String[] args) {
//Declare and Initialize an array with numbers
int[] arrayOfNumbers = new int[]{90, 453, 1, 7894, 900023, 22, 2456};
//Display even numbers
System.out.println("The numbers that are even are " + checkEvenNumbers(arrayOfNumbers));
}
}