Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 1 November 2016

Java Program to find First And Second Maximum Number From int type Array ?

Previously we Have Discussed the Program for

Here we learn the logic to write a program for finding the First and Second Maximum Number form int type Array.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class TwoMaximumNumberFromList {

   public static void method(int[] num){
   int firstMax = 0;
   int secondMax = 0;
   for(int n : num){
     if(n > firstMax){
       secondMax = firstMax;
       firstMax = n;
     }
     else if(secondMax < n){
       secondMax = n;
     }
   }
   System.out.println("FIRST MAXIMUM NUMBER : "+firstMax);
   System.out.println("SECOND MAXIMUM NUMBER : "+secondMax);
  }
  public static void main(String[] args) {
    int[] num={5,6,9,3};
    TwoMaximumNumberFromList.method(num);
  }

}

Output :

FIRST MAXIMUM NUMBER : 9
SECOND MAXIMUM NUMBER : 6




      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment