Consider an array of integers. We need to write a program that can iterate through the array and differentiate between even and odd numbers, printing the result to the console. You are given a partially completed code. Your task is to fill the blanks in the code, correctly completing the syntax for the loop condition and limit.
Iterating over arrays
Differentiating between even and odd numbers in an array
Report a typo
Fill in the gaps with the relevant elements
public class Main {
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
(int i = 0; i < ; i++) {
if (array[i] % 2 == 0) {
System.out.println("Even number: " + array[i]);
}
else {
System.out.println("Odd number: " + array[i]);
}
}
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.