Following is the code to find the second highest number from a list of numbers:
public class FindSecondMaximum { public static void main(String[] args) { int numberArr[] = {3, 43, 30, 20, 50, 44}; int max = num[0], secondMax = num[0]; for(int number :numberArr){ if (number > max) { secondMax = max; max = number; } else if(number > secondMax){ secondMax = number; } } System.out.println(secondMax); } }
Comments
Post a Comment