Advertisement
CR7CR7

Problem05

Sep 28th, 2022
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Problem05 {
  3.     public static void main(String[] args) {
  4.         Scanner scan =new Scanner(System.in);
  5.         int n =Integer.parseInt(scan.nextLine());
  6.         int sum=0;
  7.         int maxNum =Integer.MIN_VALUE;
  8.         int minNum =Integer.MAX_VALUE;
  9.         for (int i=1;i<=n;i++){
  10.              int input =Integer.parseInt(scan.nextLine()) ;
  11.              sum+=input;
  12.              if(input>= maxNum){
  13.                  maxNum=input;
  14.              }
  15.              if(input<=minNum){
  16.                 minNum=input;
  17.              }
  18.         }
  19.         double average = (double) sum / n;
  20.         System.out.printf("min = %d%n",minNum);
  21.         System.out.printf("max = %d%n",maxNum);
  22.         System.out.printf("sum = %d%n",sum);
  23.         System.out.printf("avg = %.2f%n",average);
  24.  
  25.  
  26.  
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement