(4) Write a program to store n elements in an array and retrieve the even numbers from that array.
import java.util.Random;
public class Task11
{
public static void main(String[] args)
{
& Random generator = new Random(100);
& // The length of the array
& int n = generator.nextInt(20) + 10;
& // Generating the elements of the array
& int[] numbers = new int[n];
& System.out.println("The elements of the generated array: ");
& for (int i = 0; i < n; i++)
& {
& numbers[i] = generator.nextInt(1000);
& System.out.print(numbers[i]);
& if (i < n - 1)
& System.out.print(", ");
& }
& // Outputing the even elements of the array
& System.out.println("\n\nThe even elements of the array: ");
& for (int number : numbers)
& if (number % 2 == 0)
& System.out.print(number + ", ");
& System.out.println("\b\b");
&
}
}