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 process of arranging the item of a column in some sequence or order is known as?
MatroZZZ [7]

answer: sorting??  

(hope it helps)

6 0
2 years ago
Match the context details with the pattern that applies.
tia_tia [17]

Answer:

1. - Observer

2. - iterator

3. - strategy

4. - composite

5. - decorator

Explanation:

An object contains other objects (elements) and must give access to them for clients, without exposing its internal structure. This is an observation.

The subject-object can generate events as an iterable (iterator) and could use different strategic algorithms to achieve a task. Class objects can be used to aggregate other class objects.

In python, the decorator function mimics the outer function of a nested function, but still maintains the functionality of the second function

6 0
2 years ago
Which of these statements regarding mobile games is true?
SashulF [63]

Answer:

A. They are typically played in doors.

Explanation:

Most logical answer

8 0
3 years ago
Read 2 more answers
Can you help please.
liberstina [14]
1. true
2.false
3.true
4. many - I'm not too certain of this answer
5. track changes
3 0
2 years ago
A technician needs to be prepared to launch programs even when utility windows or the Windows desktop cannot load. What is the p
ololo11 [35]

Answer:

Msinfo32.exe, cmd

Explanation:

The msinfo.exe is a tool that gathers information concerning your computer system and displays a comprehensive view of your system components, hardware, and software environment, that can later be use to diagnose computer issues.

Command Prompt is an interpreter application for command line which is available in nearly all Windows operating systems. It is utilized for executing entered commands.

6 0
3 years ago
Other questions:
  • To access WordPad, Jill will click on Start, All Programs, Accessories, and WordPad. To access Notepad, Karl will click on Start
    5·1 answer
  • 8. A pattern of being late for work or for appointments is usually
    12·1 answer
  • Assume you're running a query on your orders in the past year. You want to see how many orders were placed after May. What type
    5·1 answer
  • Which is better analog music or digital music
    15·2 answers
  • Define networks, marketplaces, and platforms and discuss their differences.
    15·1 answer
  • Help me out with this .....
    10·1 answer
  • 1. Which of the following is not related to a buffer overflow? A. Static buffer overflow B. Index error C. Canonicalization erro
    10·1 answer
  • What does it mean to catch an exception?
    8·1 answer
  • Meet.go ogle.etj-dovn-kds​
    14·1 answer
  • Which of these is not a valid form<br>layout in Microsoft Access?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!