The occurrences of the integer 2 in the array `averageSalaries`, initialize `numMatches` to 0. Increment `numMatches` when the array element is 2. Output the result after the loop.
To find the number of integers equal to 2 in the array `averageSalaries`, you can use a loop to iterate through the array and check each element. Initialize `numMatches` to 0 before the loop, and increment it whenever you find an element equal to 2. Here's the modified code:
java
import java.util.Scanner;
public class ArrayComparison {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
final int ARR_VALS = 6;
int[] averageSalaries = new int[ARR_VALS];
int i;
int numMatches = 0; // Initialize numMatches
for (i = 0; i < averageSalaries.length; ++i) {
averageSalaries[i] = scnr.nextInt();
// Check if the current element is equal to 2
if (averageSalaries[i] == 2) {
numMatches++; // Increment numMatches
}
}
System.out.println("Number of 2s in array: " + numMatches);
}
}
This code will count the occurrences of the integer 2 in the array `averageSalaries` and output the result after the loop completes.