Assign numMatches with the number of elements in userValues that equal matchValue. Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 2, 1, 2} and matchValue is 2 , then numMatches should be 3.

Your code will be tested with the following values:

* matchValue: 2, userValues: {2, 2, 1, 2} (as in the example program above)
* matchValue: 0, userValues: {0, 0, 0, 0}
* matchValue: 50, userValues: {10, 20, 30, 40}

Respuesta :

ijeggs

Answer:

public class ProblemSolution{

   public static void main(String[] args) {

   int [] userValues = {2, 2, 1, 2};

   int NUM_VALS = userValues.length;

   int matchValue = 2;

   int numMatches = 0;

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

       if(userValues[i]==matchValue){

           numMatches++;

       }

   }

       System.out.println("Number of Matches is: "+numMatches);//prints 3

   }

}

Explanation:

Using Java programming language

An array is used to hold userValues

Integer variables are declared to hold matchValue and numMatches

A for loop is used to iterate through the array elements and increase numMatches whenever the element is equal to matchValue

finally print out the numMatches

matchValue: 2, userValues: {2, 2, 1, 2} Prints 3

matchValue: 0, userValues: {0, 0, 0, 0}: Prints 4

matchValue: 50, userValues: {10, 20, 30, 40} Prints 0