Given an integer array, your task is to write a Java program that iterates over this array and prints whether each number is 'Even number' if it is an even number, or 'Odd number' if it is an odd number. Please fill in the blanks in the provided code to complete this task. Remember to use the advanced for-loop and correct branching statements in your solution.
Iterating over arrays
Determining 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[] numbers = {1, 2, 3, 4, 5};
(int num : numbers) {
if (num % 2 == 0) {
("Even number: " + num);
} else {
System.out.println("Odd number: " + num);
}
}
}
}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.