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
Tems11 [23]
3 years ago
5

Write a Java program that prompts the user to enter a sequence of non-negative numbers (0 or more), storing them in an ArrayList

, and continues prompting the user for numbers until they enter a negative value. When they have finished entering non-negative numbers, your program should return the mode (most commonly entered) of the values entered.
Computers and Technology
1 answer:
Rasek [7]3 years ago
6 0

Answer: provided in explanation segment

Explanation:

the code to carry out this program is thus;

import java.util.ArrayList;

import java.util.Scanner;

public class ArrayListMode {

 

public static int getMode(ArrayList<Integer>arr) {

      int maxValue = 0, maxCount = 0;

      for (int i = 0; i < arr.size(); ++i) {

          int count = 0;

          for (int j = 0; j < arr.size(); ++j) {

              if (arr.get(j) == arr.get(i))

                  ++count;

          }

          if (count > maxCount) {

              maxCount = count;

              maxValue = arr.get(i);

          }

      }

      return maxValue;

  }

public static void main(String args[]){

  Scanner sc = new Scanner(System.in);

  ArrayList<Integer>list= new ArrayList<Integer>();

  int n;

  System.out.println("Enter sequence of numbers (negative number to quit): ");

  while(true) {

      n=sc.nextInt();

      if(n<=0)

          break;

      list.add(n);

  }

  System.out.println("Mode : "+getMode(list));

}

}

⇒ the code would produce Mode:6

cheers i hope this helps!!!!

You might be interested in
The operations planning practice of inputting sales forecasts into computer software that accurately predicts the amount and tim
netineya [11]

Answer:

"Materials requirement planning" is the correct answer for the above question.

Explanation:

  • The "Materials requirement planning" is a software system that is used to hold the record of the raw materials.
  • It is used to tell about the material which is present in the stocks. It also used to schedule the delivery.
  • This software is used to enhance the productivity of the company.
  • The above question asked about the software which is needed to keep the record of the raw material. This software is known as "Materials requirement planning".
3 0
3 years ago
The /tmp directory is a temporary directory and will not exist on a system at all times. True or False?
jeka94

Answer:

False.

Explanation:

The /tmp directory is a directory that contains files that are required temporarily and also for temporary storage of data.The data inside the /tmp directory gets deleted when the system boots or shuts down.Since the directory exists permanently the content inside it is temporary.

So we can conclude that the answer is False.

5 0
3 years ago
Will give Brainiest and stuff to right answer[s].
Aneli [31]
#22 is 1s and 0s, hope that helps a little bit
6 0
3 years ago
Read 2 more answers
FTP is commonly used to __________ and __________ files to a server.
Aleks [24]

Answer:

upload; download

Explanation:

FTP (File Transfer Protocol) is an internet protocol used to upload and download a file to a server, there are some programs help us to transfer this data to a server, in some cases, we're going to need these programs to upload website files to the server like images or videos, or some websites where do you need a user and passwords to upload file by FTP

8 0
3 years ago
Transition words and phrase in a paragraph
balandron [24]

Answer:

Msms

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • What's the ASCII code for boy ?
    15·1 answer
  • In this exercise, you are given a word or phrase and you need to return that word or phrase with the word ‘like’ in front of it.
    5·1 answer
  • Which part of the faucet is the aerator?
    13·1 answer
  • The manager of a sports club has data about the club members' ages in a workbook. He wants to find which age is most common. Whi
    13·2 answers
  • Marys total out of pocket costbwere for the year​
    12·1 answer
  • Computer keyboard failures can be attributed to electrical defects or mechanical defects. A repair facility currently has 25 fai
    14·1 answer
  • Users of an access point share the transmission capacity of the access point. The throughput a user gets is called the ________.
    11·1 answer
  • Consider the following code snippet:
    13·1 answer
  • 6.16 LAB: Find largest number (EO) Write a method, findMax(), that repeatedly reads in integers until a negative integer is read
    9·1 answer
  • A numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score greater than 9
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!