I want to find second highest number in array in java. I tied to solve problem from this code.
class Example{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
//Random r=new Random();
int max=0;
int secondMax = 0;
for(int i=0; i<10; i++){
System.out.print("Input an integer : ");
int num = input.nextInt();
if (num>max)
{
secondMax=max;
max=num;
}
}
System.out.println("Max number is : "+max);
System.out.println("Second Max number is : "+secondMax);
}
}