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
How many passes will it take to find the four in this list?
earnstyle [38]

Answer:

3 is the correct answer

I got correct on my test

7 0
3 years ago
Read 2 more answers
Date
IRISSAK [1]

Answer:

computer is an electronic machine that accept raw data ,process and then give result. it's uses:

It is used for storing data and information.

5 0
3 years ago
Which of the following is an antivirus software?
kotegsom [21]

Answer:

McAfee

Explanation:

An antivirus is a standalone software that protects other software. On the other hand, a Firewall is capable of preserving both software and hardware on the network.

4 0
2 years ago
What describes a group of cells?<br> O crowd<br> Orange<br> O set<br> gangle
deff fn [24]

Answer:

A crowd because it makes more sense tho i could be wrong

7 0
3 years ago
Read 2 more answers
Hey yall! Its spoopy season! I am having a live stream on the Spoon app under the username teendragonqueen️‍ if yall wanna join!
Aleks [24]

Answer:

Ok sounds cool.

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Question: Henry wants to change the configuration information of an application. Which file should Henry edit to change this inf
    15·1 answer
  • A loop that repeats a specific number of times is known as a(n):
    9·1 answer
  • Which of the following statements is NOT true about a mainframe computer?
    14·1 answer
  • A cloud file system (CFS) allows users or applications to directly manipulate files that reside on the cloud.
    6·1 answer
  • A sense of scale tells us what about the objects in a picture?
    11·2 answers
  • What is the purpose of a primary key?
    5·1 answer
  • Difrent between computer and computer system​
    9·1 answer
  • Have some points part 6<br>anyone know how to change my username?​
    11·2 answers
  • You are creating a query for a website. The query
    5·1 answer
  • Connect research concepts to their definitions
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!