Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

2nd highest number from array


 static int secondHighest(int... nums) {
    int high1 = Integer.MIN_VALUE;
    int high2 = Integer.MIN_VALUE;
    for (int num : nums) {
      if (num > high1) {
        high2 = high1;
        high1 = num;
      } else if (num > high2) {
        high2 = num;
      }
    }
    return high2;
 }

Source by w3programmers.org #
 
PREVIOUS NEXT
Tagged: #highest #number #array
ADD COMMENT
Topic
Name
9+5 =