Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class Kalkulator {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         // Uzytkownik podaje najpierw ile liczb chce zsumować, a potem podaje te liczby,
  8.         // wypiszmy sume tych, ich srednia arytmetyczna,
  9.         // najwieksza liczbe, najmniejsza liczbe.
  10.  
  11.         int n = Integer.parseInt(JOptionPane.showInputDialog(null, "Podaj ilosc liczb: "));
  12.  
  13.         int tab[] = new int[n];
  14.  
  15.         for (int x = 0; x < tab.length; x++) {
  16.             tab[x] = Integer.parseInt(JOptionPane.showInputDialog(null, "Podaj liczbe: "));
  17.  
  18.         }
  19.  
  20.         double suma = 0;
  21.  
  22.         int min = tab[0];
  23.         int max = tab[0];
  24.         for (int x = 0; x < tab.length; x++) {
  25.             suma += tab[x];
  26.             if (tab[x] < min) {
  27.                 min = tab[x];
  28.             }
  29.  
  30.             if (tab[x] > max) {
  31.                 max = tab[x];
  32.             }
  33.         }
  34.  
  35.         System.out.println("Suma podanych liczb wynosi: " + suma);
  36.         System.out.println("Średnia arytmetyczna wynosi: " + suma / n);
  37.         System.out.println("Największa z podanych liczb to: " + max);
  38.         System.out.println("Najmniejsza z podanych liczb to: " + min);
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement