grodek118

Srednia elementow

Mar 24th, 2022
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4. import static java.lang.Math.*;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         System.out.println("Podaj ilosc elementow: ");
  11.         Scanner scanner = new Scanner(System.in);
  12.         int quantity = scanner.nextInt();
  13.         System.out.println("Podaj te liczby: ");
  14.         int[] numbers = new int[quantity];
  15.         double sum = 0.0;
  16.         for(int i = 0; i < quantity; i++){
  17.             numbers[i] = scanner.nextInt();
  18.             sum += numbers[i]; //sum = sum + numbers[i] -  to jest to samo
  19.         }
  20.  
  21.         double avarage = sum / quantity;
  22.         System.out.println("Srednia wynosi: " + avarage);
  23.  
  24.     }
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment