Java Program Find Second highest number in an integer array

public class FindSecondHighest{


public static void main(String [] args){
int [] numberList={9,15,6,15,18,13,11,4,12,23};
int arrayLength=0,arrayValue=0,arrayMatch=0,count=0,secondLeastValue=0;
  arrayLength=numberList.length;
  for(int i=0;i   arrayValue=numberList[i];//takes the first value from array;
  for(int j=0;j   arrayMatch=numberList[j]; //takes the first value from array;
 
  if(arrayValue count++;   //if the condition is matched counting starts.
  }
  }
 
  //One of the way for finding seconding least number
  else if(count==(arrayLength-2)){
  secondLeastValue=arrayValue;
  }
  count=0;//resetting the counter
 
  }
  System.out.println("The second Least Value "+secondLeastValue);

}
}


output: The second Least Value 9

Comments

Popular posts from this blog

Reasoning-Number Series

Reasoning-Letter Series

Profit and Loss