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
Add an array, which will store the most recent 5 recent transactions. For the array, add an insert function which will store the
Vika [28.1K]

The answer & explanation for this question is given in the attachment below.

Download docx
4 0
3 years ago
So wait how do i comment on someone's answer because that would be useful ,,.
LuckyWell [14K]

Answer:

Type right under my comment

Explanation:

Look in comments

5 0
3 years ago
Read 2 more answers
Which Computer career field enables you to create and design interactive multimedia products and service
Stells [14]
The answer is Web and Digital communications
4 0
3 years ago
Read 2 more answers
You listened to a song on your computer. did you use hardware or software? explain.
scZoUnD [109]
Software, unless you planned on permanently downloading the Music Album or Song to your computer's Hard Drive. i.e, you would use whatever Music or Media player you have installed on your computer, and that simply counts as Software. 
4 0
3 years ago
(15) What is the best definition of a contextual tab?
katen-ka-za [31]

  1. What is the best definition of a contextual tab-<u>(c) A tab that appears in context with what you are working on</u>
  2. A theme can be applied to-<u>(d) All of the answers are correct</u>

Explanation:

  1. What is the best definition of a contextual tab-<u>(c) A tab that appears in context with what you are working on</u>
  2. A theme can be applied to-<u>(d) All of the answers are correct</u>
  3. What is the difference between Reading view and Slide Show view-<u>(c) Slide Show view contains annotation tools while Reading view does not</u>
  4. Which of the following is not a view available from the Presentation Views section of the View tab-<u>(a) Slide Show</u>
  5. Where can you find the command to access slide, note, or handout masters-<u>(d) View tab</u>
  6. To rotate a text box, which handle would you use-<u>(d) You must use the commands on the Home tab</u>
  7. To change a black and white, boring presentation into something a bit more pleasing to the eye, what option would be best-<u>(b) Templates</u>
  8. The area on the top of your PowerPoint screen, as seen in the image, is commonly referred to as the what-<u>(a) Menu Options</u>
  9. What does it mean when a command button is grayed out-<u>(c) The command is disabled and requires an action first.</u>
  10. The area on a slide that holds text that will appear in the presentation outline is a-<u>(a) text box</u>
  11. To easily find a presentation that you were working on earlier today, you could-(<u>c) all of the above</u>

6 0
4 years ago
Other questions:
  • A ________ pays out cash flows from a collection of assets in different tranches, with the highest-rated tranch paying out first
    8·1 answer
  • A company wants a recruiting app that models candidates and interviews; displays the total number of interviews each candidate r
    6·1 answer
  • When you check to see how much RAM, or temporary storage you have available, you are checking your _____.
    7·1 answer
  • Which of the following describes ETL? a) A process that transforms information using a common set of enterprise definitions b) A
    14·1 answer
  • Leah wants to add an image to her updated presentation, so she wants to access the Help interface. What should
    11·2 answers
  • 11111 Power 2 sovle ​
    14·1 answer
  • Do you think Mortal Combat is cool?
    10·2 answers
  • Why are computer simulations useful in studying phenomena in the universe?
    15·1 answer
  • For which tasks is Layout view most helpful? Check all that apply.
    12·1 answer
  • A(n) ______is like an intranet except it shares its resources with users from a distant location. Select your answer, then click
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!