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