1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
SSSSS [86.1K]
3 years ago
6

Set numMatches to the number of elements in userValues (having NUM_VALS elements) that equal matchValue. Ex: If matchValue = 2 a

nd userValues = {2, 2, 1, 2}, then numMatches = 3.
import java.util.Scanner;
public class FindMatchValue {
public static void main (String [] args) {
final int NUM_VALS = 4;
int[] userValues = new int[NUM_VALS];
int i = 0;
int matchValue = 0;
int numMatches = -99; // Assign numMatches with 0 before your for loop
userValues[0] = 2;
userValues[1] = 2;
userValues[2] = 1;
userValues[3] = 2;
matchValue = 2;
Computers and Technology
1 answer:
xenn [34]3 years ago
5 0

Answer:

import java.util.Scanner;

public class FindMatchValue {

public static void main (String [] args) {

   final int NUM_VALS = 4;

   int[] userValues = new int[NUM_VALS];

   int i = 0;

   int matchValue = 0;

   int numMatches = -99; // Assign numMatches with 0 before your for loop

   userValues[0] = 2;

   userValues[1] = 2;

   userValues[2] = 1;

   userValues[3] = 2;

   matchValue = 2;

   numMatches=0;

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

   {

       if(userValues[i]==matchValue)//cheking if the array element is equal to match value.

       {

           numMatches++;

           

       }

   }

   System.out.println(numMatches);//printing the matchvalue.

}

}

Output:-

3

Explanation:

First I have set the value numMatches to 0 before the loop.Then I have user the for loop to iterate over the array.In the for loop I am checking that the array element is equal to the matchValue or not if it is equal then increasing the numMatches by 1.Then at last print the value of numMatches.

You might be interested in
Need help with Python coding from Zybooks...
ANEK [815]

Answer:

uhhhh i dont know what that is

7 0
3 years ago
HURYY PLEASE and please be the right answer!!!with reasoning
ahrayia [7]

Answer:

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

Explanation:

6 0
3 years ago
What year did buck tooth bob become famous
victus00 [196]
I tried looking at other sites to even have an idea of who this is but I couldn't find anything, sorry
6 0
3 years ago
Read 2 more answers
What are some ways to rename a worksheet? Check all that apply.
Mamont248 [21]

Answer:

Click the Home tab, click Format, click Rename Sheet, type the name, and press Enter

Explanation:

im  not really sure but i think this is the answer

have a good day

3 0
3 years ago
A coffee shop is considering accepting orders and payments through their phone app and have decided to use public key encryption
arlik [135]
Somewhat they store the credit info
8 0
2 years ago
Other questions:
  • You can drag a cell to a new location by pointing to the cell border until the pointer displays a _______ arrow, and then draggi
    9·2 answers
  • After earning a learners license what test must be successfully passed to earn an operators license in Florida
    14·1 answer
  • All waves consist of a continuous series of _____.
    11·2 answers
  • How do I turn of the noise canceling feature on my beats studio wireless?
    13·1 answer
  • After saving her presentation initially, Leah realizes she needs to add another content slide. She adds the slide and is ready t
    7·1 answer
  • Playstation network live updates pes 2018 does it cost extra
    13·1 answer
  • What is virtual memory?
    11·1 answer
  • How are some businesses capitalizing on social media at the time of someones death
    7·1 answer
  • Which keys should you press to insert a comment in OpenOffice Writer?
    15·2 answers
  • File format extension for animation are. Swf,. Swl and _____
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!