Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- /*
- * Problem Set 1
- *
- * File: Statistics.java
- * Author: JunCheng Zhang
- * Course: CS112, Boston University
- * Section: B1
- *
- * Purpose: Template code - Alter to state the purpose of this program
- */
- // The following import command is required for performing user input:
- // The Scanner class is a library which provides functionality for
- // reading input from the user in the Interactions Pane. Some
- // libraries (such as Math) are already inported, but most (such
- // as Scanner) you need to explicitly import. The import statement
- // must occur before your class definition.
- import java.util.Scanner;
- public class Statistics {
- /*
- * main method of the Statistics program which will
- * be used as the main entry point of our program and
- * to test the methods of the class.
- */
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- int num1 = console.nextInt();
- int num2 = console.nextInt();
- int num3 = console.nextInt();
- display_statistics(num1,num2,num3);
- // Enter your code
- }
- /*
- * display_statistics()
- *
- * Static method of this class which will be used to calulate and
- * display the required statistics.
- *
- * This method accepts three integer arguments as input values and uses
- * the input values to compute the statistics. This method is a void
- * method and does not return any value.
- */
- public static void display_statistics( int num1, int num2, int num3) {
- // Enter your code
- int sum = num1 + num2 + num3;
- int maxi = Math.max(Math.max(num1,num2), num3);
- int mini = Math.min(Math.min(num1,num2), num3);
- double avg = ((num1 + num2 + num3) / 3);
- // The sum of three numbers
- System.out.println(sum);
- // The maximum of the three numbers
- System.out.println(maxi);
- // The range of the numbers
- System.out.println(maxi - mini);
- // The mean(average) of the three numbers
- System.out.println(avg);
- // The (population) standard deviation of the three numbers
- System.out.println(Math.sqrt(((num1 - avg) * (num1 - avg) + (num2 - avg) * (num2 - avg) + (num3 - avg) * (num3 - avg)) / 2));
- // print out the three numbers in ascending order
- System.out.println(mini + (sum - maxi - mini)+ maxi);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement