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
What happens if you give false information on your driver license application?
Artist 52 [7]

Answer:

<em>Cancelled</em>

Explanation:

Providing false information on your driver license application will result in your license being cancelled.

Giving the DMV any false info is considered a crime.

Hope this helped!

6 0
3 years ago
An engine's _______ contains the cylinder block, the cylinders, the piston, the connecting rods, and the crankshaft assemblies.
Fittoniya [83]
The answer is C.upper end

hope this helps. Have a wonderful day 
5 0
3 years ago
Read 2 more answers
What is an example of a hard skill?
Serjik [45]
3 would be self management
4 0
3 years ago
Read 2 more answers
You manage a small LAN for a branch office. The branch office has three file servers and few client workstations. You want to us
lana66690 [7]

You manage small LAN for a branch office. The branch office has three file servers and few client workstations. You want to use Ethernet device and offer guaranteed bandwidth to each server. You design the network by <u>connecting all network devices to a switch. Connect each server to its own switch port.</u>

<u></u>

Explanation:

  • A local-area network (LAN) is a computer network that spans a relatively small area.
  • Most often, a LAN is confined to a single room, building or group of buildings, however, one LAN can be connected to other LANs over any distance via telephone lines and radio waves.
  • The LAN is the networking infrastructure that provides access to network communication services and resources for end users and devices spread over a single floor or building.
  • Designing a LAN for the campus use case is not a one-design-fits-all proposition.
  • If there is a single 48-port switch, 47 devices can be supported, with only one port used to connect the switch to the rest of the network, and only one power outlet needed to accommodate the single switch

8 0
3 years ago
3 uses of a computer ​
GenaCL600 [577]

Answer:

online bills payment

watching movies or shows

home tutoring

3 0
2 years ago
Read 2 more answers
Other questions:
  • Technological _____ is the term used to describe the merging of several technologies into a single device.
    13·1 answer
  • Integrated circuits are made up of _____ and carry an electrical current
    14·1 answer
  • explain the key reasons why entity relationship modeling is important, and determine at least (1) way in which it impacts the ov
    5·1 answer
  • We must know the Inflation Rate and the Nominal GDP in order to calculate Real GDP.
    15·1 answer
  • Suppose the file is sent continuously as one big message. how long does it take to send the file, assuming it is sent continuous
    15·1 answer
  • The domain name service (dns is a distributed database that allows users to communicate with each other computers by:
    7·1 answer
  • Who created fortnite
    15·2 answers
  • Jasmine wants electrical current to be able to pass through a certain switch on a circuit board that she is designing. What stat
    5·1 answer
  • A local pizza shop is selling a large pizza for $9.99. Given the number of pizzas to order as input, output the subtotal for the
    12·1 answer
  • This question involves the creation and use of a spinner to generate random numbers in a game. a gamespinner object represents a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!