Advertisement
davegimo

minmax

Mar 3rd, 2021
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. public class HelloWorld{
  2.  
  3.      public static void main(String []args){
  4.        
  5.         int[] a = {3,5,6,7,1,6,8,11,1000,1,5,5,5342,56,3};
  6.        
  7.         int max = a[0];
  8.         int min = a[0];
  9.         for (int i = 0; i < a.length; i++) {
  10.             if (a[i] > max) {
  11.                 max = a[i];
  12.             }
  13.             if (a[i] < min) {
  14.                 min = a[i];
  15.             }
  16.         }
  17.        
  18.         System.out.println(max);
  19.         System.out.println(min);
  20.        
  21.        
  22.        
  23.      }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement