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
Which of the following is NOT a font style?<br> Italic<br> Bold<br> Regular<br> Iconic
madam [21]

Answer:

iconic

Explanation:

iconic iconic iconic

8 0
3 years ago
Read 2 more answers
What type of measurement are each of the following
bixtya [17]

Answer:

unities

Explanation:

Every one may be counted in unities

3 0
3 years ago
15 POINTS! please help
Maksim231197 [3]

Answer:

1. Understand your audience

2. Add a header

3. Put a face to the name

4. Write a professional headline

5. Be contactable

6. Summarize your story

7. Showcase your experience

8. Let your network speak for you

Hoped this helped

8 0
3 years ago
Read 2 more answers
Given the following table of students, assignments, and grades for a single class:
PilotLPTM [1.2K]

Answer:

i need more

Explanation:

i need more

7 0
3 years ago
What is the internet protocol that web browsers use to request and display web pages using universal resource locators?
Rzqust [24]
HTTP protocol, stands for HyperText Transfer Protocol
6 0
3 years ago
Other questions:
  • _______ computing refers to applications and services that run on a distributed network using virtualized resources.
    14·1 answer
  • Hacker is a person who illegally breaks into a system or network without any authorization to destroy, steal sensitive data or t
    14·1 answer
  • Write the half function. A function call and the functionprototype
    12·1 answer
  • Which of the following things must you do if you are parked on a rural highway?
    8·1 answer
  • ____ steganography places data from the secret file into the host file without displaying the secret data when you view the host
    9·1 answer
  • identify at least three additional ethical responsibilities expected from a computer professional. In brief, explain each respon
    11·1 answer
  • Windows Rights Management Services is used in conjunction with which Microsoft applications?
    11·1 answer
  • Beyond adding equations, what else does the Insert Equation feature allow users to do?
    7·1 answer
  • You need to know more than just facts in order to use critical thinking skills.
    5·1 answer
  • Explain briefly how learning how to follow can make a person a good leader
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!