javatechie

Find Max and Min Element From Array

Sep 23rd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. package com.javatechie.solution;
  2.  
  3. public class Array_Max_Min {
  4.     public static void main(String[] args) {
  5.         int[] num = { 90, 24, 46, 35, 32, 12, 98, 2 };
  6.         int max = num[0];
  7.         int min = num[1];
  8.  
  9.         for (int i = 0; i < num.length; i++) {
  10.             if (num[i] > max) {
  11.                 max = num[i];
  12.             } else if (num[i] < min) {
  13.                 min = num[i];
  14.             }
  15.         }
  16.  
  17.         System.out.println("Max Element is " + max);
  18.         System.out.println("Min Element is " + min);
  19.     }
  20. }
Add Comment
Please, Sign In to add comment