Java Code Example: even numbers in an array

The code defines a Java class called EvenNumbersInArray. This class has a main method that defines an array of integers and uses a for loop to iterate through the array.

In the loop, if the element at the current index i of the array is evenly divisible by 2 (i.e., if its remainder when divided by 2 is equal to 0), it is printed to the console. This means that the code will print out only the even numbers from the array.

The array numbers has nine elements, each being a positive integer. The for loop iterates over the array, and for each iteration, the if condition checks if the current element is an even number by checking if its remainder when divided by 2 is 0. If the condition is true, the current element is printed to the console.

import java.util.Scanner;

public class EvenNumbersInArray {
    public static void main(String[] args) {
        int numbers[] = { 65, 34, 23, 75, 76, 33, 12, 9, 44 };

        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] % 2 == 0) {
                System.out.print(numbers[i] + " ");
            }
        }
    }
}
Output
34 76 12 44