Question

In: Computer Science

Statistics are often calculated with varying amounts of inputdata. Write a program that takes any...

Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics

Solutions

Expert Solution

import java.util.Scanner;

public class Statistics {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
      
       int count=0,max=-1,n;
       double sum=0,avg=0;
       System.out.println("Enter integers (negative integer to quit) : ");
       while(true) {
           //reading integer
           n=sc.nextInt();
           //if it is negative than break the loop
           if(n<0)
               break;
           count++;
           // if max is less than current number than update max to current number
           if(max                max=n;
           sum+=n;
       }
       //finding average
       avg=sum/count;
       System.out.println("Max number : "+max);
       System.out.println("Average: "+avg);
   }
}


Related Solutions

Statistics are often calculated with varying amounts of input data. Write a program that takes any...
Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is 15 20 0 5 -1, the output is: 10 20 You can assume that at least one non-negative integer is input. Can this be written in CORAL please!!
Statistics are often calculated with varying amounts of input data. Write a program that takes any...
Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics.
in c++ pleaseStatistics are often calculated with varying amounts of inputdata. Write a program...
in c++Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics.Ex: When the input is 15 20 0 5 -1, the output is:10 20You can assume that at least one non-negative integer is input.
Forms often allow a user to enter an integer. Write a program that takes in a...
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or any string with a non-integer character, the output is: no PYTHON 3
Write a program CurrencyConverter.java (in a package named a02) that takes currency amounts in Euros (EUR),...
Write a program CurrencyConverter.java (in a package named a02) that takes currency amounts in Euros (EUR), US Dollars (USD) and Japanese Yen (JPY) as command line arguments and converts them to Canadian dollars (CAD). The correct format for each command line argument is as follows: the 3-character currency code (ignoring upper or lower case); followed by one or more digits; followed by the decimal point '.'; followed by 2 digits. Some examples of valid arguments are: JPy57687.34 USD0.34 eur30.00 Some...
Forms often allow a user to enter an integer. Write a programthat takes in a...
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9
Write a program in Python that - Takes in a gross salary. - If the gross...
Write a program in Python that - Takes in a gross salary. - If the gross salary is above €50.000 taxes are 50%. - If the gross salary is above €25.000 taxes are 25%. - If the gross salary is above €10.000 taxes are 10%. - If the gross salary is below €10.000 there is no tax. - Output the gross salary and the net income. Note: Give the pseudocode of your program.
Write a program that can be used to calculate the federal tax. The tax is calculated...
Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows: If the taxable income is: Between $0 and $15,000, the tax rate is 15%. Between $15,001 and $40,000, the tax is $2,250...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
1. Write a program in C++ that takes as inputs a positiveinteger n and a...
1. Write a program in C++ that takes as inputs a positive integer n and a positive double a. The function should compute the geometric sum with base a up to the powern and stores the result as a protected variable. That is, the sum is: 1 + ? + ? ^2 + ? ^3 + ? ^4 + ⋯ + ? ^?2.  Write a program in C++ that takes as input a positive integer n and computes the following productsum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT