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
File Account.java contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and a
puteri [66]

The answer & explanation for this question is given in the attachment below.

Download docx
5 0
3 years ago
Write an expression that executes the loop body as long as the user enters a non-negative number.
Grace [21]

Answer:

user_num = 9

while user_num > -1:

 print("Body")

 user_num = int(input())

print("Done")

If this answer helped consider rating and marking brainliest :)

7 0
2 years ago
Read 2 more answers
Imagine how the situation could be handled. Come up with as many ideas as possible: There's no one "right" answer! Then, highlig
Veseljchak [2.6K]

Answer:

there is no passage

Explanation:

6 0
3 years ago
What is the correct order for writing the 3 dimensions for a 3D object? Here are the 3 dimensions:
Nady [450]

Answer:

Length x Width x Hight

Explanation:

3 0
3 years ago
What type of system enables computer data to be stored in multiple locations and shared with multiple users simultaneously?
Alexandra [31]

Answer:

A

Explanation:

3 0
3 years ago
Other questions:
  • Coretta is thinking about which careers she would enjoy. She considers her personal skills and interests. She enjoys reading and
    13·2 answers
  • How has social media changed professional networking?
    11·1 answer
  • Explain the nature of documents that can be suitable for mergin
    12·1 answer
  • Create a function named PrintStudents, which takes a string input filename and an integer minimum score value and a string outpu
    14·1 answer
  • Write the SQL query that would search a table called Movies and return the titles of movies that were made in 1975.
    7·1 answer
  • A relational database has been created to store data about subjects that students are studying. The following is a
    11·1 answer
  • Why are Quick Parts useful in an Outlook message?
    10·2 answers
  • You can have more that one image open at a time in GIMP. True or false
    10·1 answer
  • Why would you choose a mobile device over a laptop? 1-2 sentences.
    11·1 answer
  • what is the name of the program that enables the device and operating system to communicate with each other?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!