Write a java program to find second maximum?
/* Java Program to find second maximum number*/
public class SecondMaximum {
public static void main(String[] args) {
int[] array = {1,2,34,156,436,3};/* give input here*/
int firstMax = 0;
int secondMax= 0;
for(int i = 0; i<array.length;i++){
if(firstMax < array[i]){
secondMax = firstMax;
firstMax = array[i];
}
}
System.out.println("First Max Number: "+firstMax);
System.out.println("Second Max Number: "+secondMax);
}
}