Chardakliev

Min Max Sum Average

Feb 5th, 2022 (edited)
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         // declare data
  8. // initialize counters and accumulators
  9.         double sum = 0;
  10.         double max = -10000;
  11.         double min = 10000;
  12.  
  13.         double num = 0;
  14.  
  15.         for (int counter = 0; counter < 4; counter++) {
  16.             num = scanner.nextInt();
  17.             if (num > max) max = num;
  18.             if (num < min) min = num;
  19.             sum += num;
  20.  
  21.  
  22.             }
  23.         double avg = sum / 4;
  24.  
  25.  
  26.             System.out.printf("min=%.2f%n", min);
  27.             System.out.printf("max=%.2f%n", max);
  28.             System.out.printf("sum=%.2f%n", sum);
  29.             System.out.printf("avg=%.2f", avg);
  30.  
  31.  
  32.         }
  33.     }
  34.  
  35.  
  36.  
RAW Paste Data Copied