Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1.  
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         int tab2[] = { 4, 3, 8, 1, 5 };
  8.  
  9.         int min = tab2[0];
  10.         int max = tab2[0];
  11.  
  12.         for (int x = 0; x < tab2.length; x++) {
  13.             // tab[x] = Integer.parseInt(JOptionPane.showInputDialog("Podaj liczbe: "));
  14.  
  15.             // suma+=tab[x];
  16.  
  17.             if (tab2[x] < min) {
  18.                 System.out.println("min");
  19.                 min = tab2[x];
  20.             }
  21.  
  22.             if (tab2[x] > max) {
  23.                 System.out.println("max");
  24.                 max = tab2[x];
  25.             }
  26.         }
  27.  
  28.         System.out.println("Największa z podanych liczb to: " + max);
  29.         System.out.println("Najmniejsza z podanych liczb to: " + min);
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement