Respuesta :

Answer:

public class Match

{

public static void main(String[] args) {

 final int NUM_VALS = 4;

       int[] userValues = new int[NUM_VALS];

       int matchValue, numMatches = 0;

       userValues[0] = 2;

       userValues[1] = 2;

       userValues[2] = 1;

       userValues[3] = 2;

   

       matchValue = 2;

   

       for(int i = 0; i < NUM_VALS; ++i) {

           if(userValues[i] == matchValue)

               numMatches++;

       }        

       System.out.println("Match Value: " + matchValue + ", Number of Matches: " + numMatches);

}

Explanation:

- Initialize the userValues array with length of NUM_VALS, which is initialized as 4

- Assign the numbers to the userValues array

- Update matchValue as 2

- Initialize a for loop that iterates through userValues array. If a number that is equal to matchValue found in array, increase the numMatches by 1

- Print the matchValue and numMatches