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
Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you
marishachu [46]

import random

num_rolls = 0

while True:

   r1 = random.randint(1, 6)

   r2 = random.randint(1, 6)

   print("Rolled: " + str(r1) + "," + str(r2))

   num_rolls += 1

   if r1 == r2 == 1:

       break

print("It took you "+str(num_rolls)+" rolls")

I added the working code. You don't appear to be adding to num_rolls at all. I wrote my code in python 3.8. I hope this helps.

4 0
3 years ago
Forms open in _______, which provides a user-friendly interface for entering data.
sergey [27]
They open in pdf format

5 0
3 years ago
Before you insert a page break, what should you do? select the font you want to use for the text that comes after the page break
Triss [41]
Put the insertion point where you want the page to break is what I would write.
7 0
3 years ago
Given a String variable named sentence that has been initialized, write an expression whose value is the number of characters in
Troyanec [42]
Python:

sentence = “this is the sentence.”
size = len(sentence)

C++:

string sentence = “this is the sentence.”
int size = sentence.size()

* Remember strings are just arrays of characters.

5 0
3 years ago
[C++ for array week|
melamori03 [73]

Answer:

this is stupi

Explanation:

8 0
3 years ago
Other questions:
  • Below is a chart representing portions of resumes from 3 applicants. Which best explains the applicants careers?
    11·1 answer
  • Which is NOT a type of SD card?
    8·2 answers
  • trhy356<br>yjetyi46ui y j4yhnpug 2utg[ 2[ 24[ou [o24t
    15·1 answer
  • In Microsoft Word, how would you change the amount of space that is put in after each paragraph?
    15·1 answer
  • How do I make my own extension for chrome?
    7·1 answer
  • Complete the statement using the correct term.
    6·1 answer
  • The physical layer of the OSI model is not foundational to any of the other layers. True or False
    8·1 answer
  • Write a program that computes how much each person in a group needs to pay (after tax and tip) when splitting the bill equally.
    5·1 answer
  • How do you enlarge an image to see more detail on it? (1 point)
    14·2 answers
  • What is business agility
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!