Finding values in an array
Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 1, 2, 2} and matchValue is 2 , then numMatches should be 3.
Your code will be tested with the following values:
matchValue: 2, userValues: {2, 1, 2, 2} (as in the example program above)
matchValue: 0, userValues: {0, 0, 0, 0}
matchValue: 10, userValues: {20, 50, 70, 100}
1 import java.util.Scanner:
2
3 public class FindMatchValue {
4 public static void main(String args) {
5 Scanner ser-new Scanner(System.in); lioli
6
7 final int NUM_VALS = 4
8 into userValues - new int [NUM VALS);
9 int i;
10 int matchWalue;
11 int nurMatches - -99; // Assign nurlatches with before your for loop
12
13 matchValue - scnr.nextInt():
14 for (i = 0; i < uservalues.length; ++) {
15 userValues() - senr .nextInt();
16 }

Respuesta :

Answer:

The following code completes the program

for (i = 0; i < userValues.length; i++) {

     if(userValues[i] == matchValue){

         nuMatches++;

     }  }

 System.out.println(nuMatches);

Explanation:

The question is poorly formatted. So, I correct the poorly formatted program segment and I complete the missing part of the program.

See attachment for complete program.

The explanation is as follows:

This iterates through the array

for (i = 0; i < u s e r V a l u e s. length; i++) {

This checks if the current array element is the same as the match value

     if(userValues[i] == matchValue){

If yes, the number of matches is increased by 1

         nuMatches++;

     }  }

This prints the number of matches

 System.out.println(nuMatches);

Ver imagen MrRoyal