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 is one reason why a business may want to move entirely online?
andrezito [222]

Answer:

To focus on global market

Explanation:

Hope this helps! :)

3 0
2 years ago
Có n chiếc kẹo và m em bé. Hãy viết chương trình nhập vào hai số nguyên dương n, m và kiểm tra n chiếc kẹo có chia đều được cho
sleet_krkn [62]

uy ako ba yung pilipino dito hi nga kau

5 0
2 years ago
What is computer ? What is computer program? What is hard disk.
g100num [7]
A computer is a electronic that helps you access the internet/WiFi
4 0
3 years ago
Read 2 more answers
Write code that read from variables N and M, multiply these two unsigned 32-bit variables and store the result in Variables P, Q
Tamiku [17]

Answer:

Using C language;

#include <stdio.h>

int main()

{

int N, M;

printf("Please enter two numbers: ");

scanf("%d %d", &N, &M);

int P,Q = N*M;

return 0;

}

Explanation:

The variables N and M are declared and the "scanf" function is used to assign a value to the variables from the input prompt, then the product of N and M are saved to the P and Q variables.

8 0
3 years ago
How can I link two classes together with spigot to make it so I can open a method within the said class. Trying to open my class
Andreyy89

Answer:

add the following code to your bar class

Explanation:

public Bar(Commands n) { }

5 0
2 years ago
Other questions:
  • A software license gives the owner the to use software.
    12·2 answers
  • You can display content variations to mobile, tablet or desktop users.
    12·1 answer
  • What do you think about the future of computers?​
    14·1 answer
  • What does the action tool allow you to do in Microsoft power point?
    9·1 answer
  • Explain what middleware is. Name a common middleware in two-tier client/server architecture for database applications.
    10·1 answer
  • How many strings with five or more characters can be formed from the letters in seeress?
    15·1 answer
  • Viết thuật toán, chương trình xử lý hạn chế trong việc xử lý số liệu phần nguyên để hiển thị lên lcd
    14·1 answer
  • Brainly is brainly am I correct ​
    11·2 answers
  • How do u delete a post on brainly
    7·1 answer
  • Question 1 (1 point)
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!