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
Gnoma [55]
4 years ago
15

g 4.16 Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative inte

ger ends the input and is not included in the statistics. Ex: When the input is:
Computers and Technology
1 answer:
pashok25 [27]4 years ago
8 0

Answer:

import java.util.ArrayList;

import java.util.Scanner;

import java.util.Collections;

public class num4 {

   public static void main(String[] args) {

       int sum = 0;

       Scanner in = new Scanner(System.in);

       System.out.println("Enter number");

       int num = in.nextInt();

       ArrayList<Integer> list = new ArrayList<>();

       while (num >= 0){

       list.add(num);

       System.out.println("Enter another positive number, enter a negative to stop");

       num = in.nextInt();

       }

       int maximum = Collections.max(list);

       int listSize = list.size();

       for(int i:list){

           sum = sum+i;

       }

       double average = (double) sum/listSize;

       System.out.println("Maximum number entered is "+maximum);

       System.out.println("Average of the number is "+average);

   }

}

Explanation:

In this program:

  • A Scanner class is used to receive user input and store in a variable
  • A while loop with the condition while (num >= 0) is used to ensure only non-negative numbers are entered
  • An ArrayList is created and used to store all the user's valid entries
  • The Max Method in the Collections class is used to find the maximum value entered
  • To find the average, a for loop is used to add all elements in the list and divide by the size of the list
  • Finally the Average and maximum is printed out
You might be interested in
What is an example of a one-to-many relationship?
jok3333 [9.3K]
Last option o si employee is
8 0
3 years ago
Read 2 more answers
Does anyone else realize how the only tutor is for math never any other subjects?​
Slav-nsk [51]

Answer:

yes I do and I wonder why ??

7 0
3 years ago
Which group of Indians was native to Roanoke and not very friendly?
uysha [10]

Answer:

Croatan I think if I remember it right.

Explanation:

5 0
4 years ago
Read 2 more answers
What are slicers used for?
Pachacha [2.7K]

Answer:

Quickly filtering data

Explanation:

Just did the Excel instruction for Edge 2021

Plz click the Thanks button

<Jayla>

4 0
3 years ago
Consider the following scenario. As you troubleshoot the problem, what motherboard device would be the first to
prohojiy [21]
Check if the board is getting power, if it isn’t, than you may have a power supply issue.
8 0
3 years ago
Other questions:
  • Computer communications describes a process in which two or more computers or devices transfer ____.
    10·1 answer
  • How to put vibratuon when tapping on keyboard galaxy s3?
    5·1 answer
  • Which is a difference between the systems development life cycle (SDLC) and extreme programming (XP)?
    7·1 answer
  • Where does the Total row of an aggregate function display its results? First row in Datasheet view Only row in Datasheet view La
    10·1 answer
  • Which statement is true for rapid prototyping? (A. It creates a two-dimensional model of a part or a product, from the original
    8·2 answers
  • If you Buy my group clothing in R.o.b.l.o.x for a donation i will make you brainliest
    14·2 answers
  • Create a high-level plan to perform a gap analysis for Fullsoft Inc
    7·1 answer
  • You are going to visit a national park, and have never been there before. You are using a map to try and make the distance trave
    11·1 answer
  • Which of the following is a method which can be used to delete a page from a publication?
    6·1 answer
  • A ______ system writes data on two or more disks simultaneously, thereby creating a complete copy of all the information on mult
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!