132k views
1 vote
What does the following loop do?int[] a = {6, 1, 9, 5, 12, 3};int len = a.length;int x = 0;for (int i = 0; i < len; i++)if (a[i] % 2 == 0) x++;System.out.println(x);1. Sums the even elements in a.2. Finds the largest value in a.3. Counts the even elements in a.4. Finds the smallest value in a.

User Jughead
by
4.9k points

1 Answer

2 votes

Answer:

The answer is "Option 3"

Explanation:

The description of the above java code can be given as:

  • In the given code an array initialized elements in the next line an integer variable that is "len" is define this variable holds a length of the array and another variable "x" is defined that holds value 0.
  • Then we use loop in loop a conditional statement is used that checks in array if any number is even. If this condition is true so the value of x variable increases by 1 and prints its value.
User ObsessiveCookie
by
5.6k points