/********************************************************** * class MathStats * * Description: Demonstrates user input, output, using * assignment operators, and using the * Math class * * Input: The user enters 3 integers. * * Output: Print the 3 integers the user entered, the sum * of the 3 integers, the average, the sum squared, * and the square root of the sum. **********************************************************/ import java.io.*; // for reading keyboard input public class MathStats { static final int NUM = 3; static BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in)); public static void main (String[] args) throws IOException { int num1, num2, num3; int sum = 0; double average, sumSqrt; double sumSquare; /******************************************* * Ask the user for an integer three times. * Store the integer and add it to the sum. *******************************************/ System.out.print ("Enter an integer: "); num1 = Integer.parseInt(keyboard.readLine()); sum += num1; System.out.print ("Enter an integer: "); num2 = Integer.parseInt(keyboard.readLine()); sum += num2; System.out.print ("Enter an integer: "); num3 = Integer.parseInt(keyboard.readLine()); sum += num3; /********************************************* * Compute the average, the square of the sum * and the square root of the sum *********************************************/ average = (double) sum / NUM; sumSquare = Math.pow (sum, 2); sumSqrt = Math.sqrt (sum); int x = (int) Math.round(sum); /********************************************* * Output the final results to the user. *********************************************/ System.out.println ("The numbers are " + num1 + ", " + num2 + ", " + num3); System.out.println ("The sum is " + sum); System.out.println ("The average is " + average); System.out.println ("The sum squared is " + sumSquare); System.out.println ("The square root of the sum is " + sumSqrt + ", or about " + Math.round(sumSqrt)); } // end of main method } // end of MathStats class