Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Kalkulator {
- public static void main(String[] args) {
- // Uzytkownik podaje najpierw ile liczb chce zsumować, a potem podaje te liczby,
- // wypiszmy sume tych, ich srednia arytmetyczna,
- // najwieksza liczbe, najmniejsza liczbe.
- int n = Integer.parseInt(JOptionPane.showInputDialog(null, "Podaj ilosc liczb: "));
- int tab[] = new int[n];
- for (int x = 0; x < tab.length; x++) {
- tab[x] = Integer.parseInt(JOptionPane.showInputDialog(null, "Podaj liczbe: "));
- }
- double suma = 0;
- int min = tab[0];
- int max = tab[0];
- for (int x = 0; x < tab.length; x++) {
- suma += tab[x];
- if (tab[x] < min) {
- min = tab[x];
- }
- if (tab[x] > max) {
- max = tab[x];
- }
- }
- System.out.println("Suma podanych liczb wynosi: " + suma);
- System.out.println("Średnia arytmetyczna wynosi: " + suma / n);
- System.out.println("Największa z podanych liczb to: " + max);
- System.out.println("Najmniejsza z podanych liczb to: " + min);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement