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
Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a
NemiM [27]

Answer:    

Here is the Encyclopedia class:

public class Encyclopedia extends Book {   //class  Encyclopedia that inherits from class Book

  private String edition; //declare private member variable edition of type String  

  private int numVolumes;      //declare private member variable numVolumes of type int

  public void setEdition(String ed) {  //mutator method of class that sets the value of edition

     edition = ed;    }     //assigns the value of ed to edition member field

  public void setNumVolumes(int numVol) { //mutator method of class that sets the value of numVol

     numVolumes = numVol;    }  //assigns the value of numVolumes to edition member field

  public String getEdition() {  //accessor method to get the value of edition

     return edition;    }     //returns the current value of edition

  public int getNumVolumes() {  //accessor method to get the value of numVolumes

     return numVolumes;    }       //returns the current value of numVolumes

  public void printInfo() {  //method to print edition and number of volumes information on output screen

     super.printInfo();  // The super keyword refers to parent class Book objects. It is used to call Book method and to eliminate the confusion between Book class printInfo method and Encyclopedia printInfo  method

     System.out.println("   Edition: " + edition);  //prints edition info

     System.out.println("   Number of Volumes: " + numVolumes);    }  }  //prints number of volumes info

Explanation:

The explanation is provided in the attached document.

7 0
4 years ago
True or false: Because there are so many different network configurations, operating systems, and strategies, it is a challenge
m_a_m_a [10]

Answer:

I think the answer is "true."

Explanation:

Because as you may know, there are many hackers and types of people who get private information from people. And different organizations must work together like you said. This requires a lot of brainstorming and connecting. It's a challenge because it needs many ideas, needs a lot of time for thinking, and making sure whatever they are doing is safe. (This is in my opinion)

3 0
3 years ago
to create an app for a mobile device, yourself, you would use BLANK software like Swift, Corona or Scratch.
stiv31 [10]
True

All the programming languages mentioned above synchronizes best with contemporary mobile platforms. Corona, for instance, is built on the programming language LUA and is used in the creation of Android mobile apps, primarily games. 

Swift on one hand is best for an apple creation (IOS and OSX). Swift is an open source which is extremely easy to learn, and is the future of mobile app development. 

On the other hand, scratch is a programming language where children can program and is used as an introductory language. Skills learned from using scratch can be applied to other basic languages like Java and python.

7 0
3 years ago
Write a recursive method called repeat that accepts a string s and an integer n as parameters and that returns s concatenated to
svp [43]

Answer:

public static String repeat(String text, int repeatCount) {

   if(repeatCount < 0) {

       throw new IllegalArgumentException("repeat count should be either 0 or a positive value");

   }

   if(repeatCount == 0) {

       return "";

   } else {

       return text + repeat(text, repeatCount-1);

   }

}

Explanation:

Here repeatCount is an int value.

at first we will check if repeatCount is non negative number and if it is code will throw exception.

If the value is 0 then we will return ""

If the value is >0 then recursive function is called again untill the repeatCount value is 0.

6 0
3 years ago
Accepted identifier for a variable in PHP except:
olganol [36]

Answer:

b. & Puihaha

Explanation:

PHP variables are supposed to start with a $ sign.

Other rules followed by PHP variables are:

Starting character in variable name (after $) must be letter or _.

Other characters in variable names can be letters,numbers or _.

a. $_Puihaha

c. $Pui_haha

d. $Puihaha

satisfy these rules.

Whereas , b. & Puihaha does not satisfy as it starts with '&'. Moreover it also contains an invalid space character in the variable.

3 0
3 years ago
Other questions:
  • 38. Which of the following best describes why e-mail spoofing is easily executed? a. SMTP lacks an adequate authentication mecha
    15·1 answer
  • What does it mean when you mail is labled unable to forward for review
    5·1 answer
  • Excel allows you to rotate text in a cell counterclockwise by entering a number between -1 degrees and -90 degrees. True or fals
    14·1 answer
  • A green screen should be lit with which two lights?
    6·2 answers
  • 1. Before operating any power tool, you need to
    14·1 answer
  • Which do switches create?<br> Networks<br> Wireless access points<br> Routes<br> Collision domains
    5·1 answer
  • Hey you know Python? Could you help me, please? It's for my Final please help me SOS.
    8·1 answer
  • All the read/write heads a hard disk are controlled by a(n) ____ which moves the read/write heads across the disk surfaces in un
    13·1 answer
  • Any action that causes harm to your computer is called a
    15·1 answer
  • .WAP to enter monthly sale of Salesman and give him commission i.E. If the monthly sale is more than 500000 then commision will
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!