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 :

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    final int NUM_VALS = 4;

    int[] userValues = new int[NUM_VALS];

    int numMatches = 0;

   

    System.out.print("Enter the match value: ");

    int matchValue = input.nextInt();

   

   

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

        System.out.print("Enter the value: ");

        userValues[i] = input.nextInt();

    }

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

           if (matchValue == userValues[i]){

              numMatches ++;

        }

    }

    System.out.println("There are " + numMatches + " " + matchValue + "'s in the user values.");

}

}

Explanation:

Initialize the variables

Ask the user to enter the match value

Create a for loop to get the user values

Create another for loop to check if the match value is equal to any of the user values. If it is, increment the number of matches by 1

When the loop is done, print the number of matches and the match value