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 to demonstrate the use of InetAddress. The program takes a list of names...
Write a program to demonstrate the use of InetAddress. The program takes a list of names or IP addresses as command line parameters and prints the name and an IP address of the local host, followed by names and IP addresses of the hosts specified on the command line. use java program
Write a Java program 1-)write a program that simulates a vending machine, takes input from the...
Write a Java program 1-)write a program that simulates a vending machine, takes input from the user (money), and returns the change to the user. The change means Quarter =   25 cent Dime = 10 cent Nickels = 5 cent Pinneies = 1 cent 2-) What is the output produced by the following code? int result = 11; result /= 2; System.out.println("resu lt is " + result);
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 in C that takes the length and the integers to be stored in...
Write a program in C that takes the length and the integers to be stored in an array and shifts array by N positions. Example: Input the number of elements to store in the array (max 10) : 5 Input 5 integers to be stored : Index - 0 : 12 Index - 1 : 29 Index - 2 : 68 Index - 3 : 32 Index - 4 : 97 Input number of shifts : 2 Expected Output :...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT