Denis_Hristov

ArrStat

Jun 8th, 2021 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ArrStat {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         System.out.println("Input numbers: ");
  8.  
  9.         String text = scan.nextLine();
  10.         String [] splitText = text.split(" ");
  11.  
  12.         int min = Integer.MAX_VALUE;
  13.         int max = Integer.MIN_VALUE;
  14.         double sum =0;
  15.         double avg = 0;
  16.  
  17.  
  18.  
  19.         for (int i = 0; i < splitText.length; i++) {
  20.             int CurrentSum = Integer.parseInt(splitText[i]);
  21.             sum+=CurrentSum;
  22.  
  23.             if (CurrentSum > max){
  24.                 max = CurrentSum;
  25.             }else if(CurrentSum < min){
  26.                 min = CurrentSum;
  27.             }
  28.  
  29.         }
  30.         avg = sum/splitText.length;
  31.  
  32.         System.out.println("Min: " + min + " Max: " + max + " Sum: " + sum + " Average: " + avg);
  33.     }
  34. }
  35.  
Add Comment
Please, Sign In to add comment