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 computer code?<br> A. Java Script<br> B. XML<br> C. HTML<br> D. Any programming language
andrey2020 [161]

Answer:

D

Explanation:

8 0
2 years ago
Define get_date() function.
lyudmila [28]

Answer:

I believe it returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.

8 0
3 years ago
The capability of moving a completed programming solution easily from one type of computer to another is known as ________. Grou
Vlad [161]

Answer: <em><u>Portability</u></em>

Explanation: I hope it helps you!

4 0
2 years ago
Write a function called first_last that takes a single parameter, seq, a sequence. first_last should return a tuple of length 2,wh
motikmotik

Answer:

The Python code with the function is given below. Testing and output gives the results of certain chosen parameters for the program

Explanation:

def first_last(seq):

   if(len(seq) == 0):

       return ()

   elif(len(seq) == 1):

       return (seq[0],)

   else:

       return (seq[0], seq[len(seq)-1])

#Testing

print(first_last([]))

print(first_last([1]))

print(first_last([1,2,3,4,5]))

# Output

( )

( 1 , )

( 1 , 5 )

5 0
3 years ago
Write a function:
Elden [556K]

Answer:

what are the choices

:"

Explanation:

5 0
2 years ago
Other questions:
  • Which of the following is the main consideration when choosing an appropriate outlet box?
    7·2 answers
  • Egyptian hieroglyphs were part of a writing system used by the ancient Egyptians. What type of graphic design elements did they
    13·1 answer
  • A______ is a graphical representation of numeric data.
    8·1 answer
  • An overall indication of the dependability of data may be obtained by examining the ________, credibility, reputation, and _____
    15·2 answers
  • Fill up the blank:- The picture that graphically represents the items you use in Windows is called a/an .......
    5·1 answer
  • Pride Group of Companies is making tremendous profits in different categories of electronic goods. The group of managers have to
    12·1 answer
  • If a employee has a grade grater than or equal to 18, then he she will get 50% bonous on the basic pay. Otherwise, the employee
    5·1 answer
  • what is the term for software that is exclusively controlled by a company, and cannot be used or modified without permission?
    6·1 answer
  • In what medium do web applications operate?
    8·1 answer
  • Energy/power management systems, kitchen appliances, smart televisions, baby monitors, fitness trackers, and personal health mon
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!