This Logic so efficient,when second highest number is input,that only assign a number.
CODING:
import java.util.Scanner;
class Hightest{
public static void main(String args[])
{
Scanner n=new Scanner(System.in);
int temp,fi_hi=0,se_hi=0;
System.out.print("How Many Enter number...");
for(int i=n.nextInt();i>0;i--){
System.out.print("Enter Number : ");
temp=n.nextInt();
if(fi_hi>temp && temp>se_hi){
se_hi=temp;
}
else if(temp>fi_hi){
se_hi=fi_hi;
fi_hi=temp;
}
}
System.out.println("Second Hightest Number :" + ((se_hi==0) ? se_hi=fi_hi : se_hi));
}
}
class Hightest{
public static void main(String args[])
{
Scanner n=new Scanner(System.in);
int temp,fi_hi=0,se_hi=0;
System.out.print("How Many Enter number...");
for(int i=n.nextInt();i>0;i--){
System.out.print("Enter Number : ");
temp=n.nextInt();
if(fi_hi>temp && temp>se_hi){
se_hi=temp;
}
else if(temp>fi_hi){
se_hi=fi_hi;
fi_hi=temp;
}
}
System.out.println("Second Hightest Number :" + ((se_hi==0) ? se_hi=fi_hi : se_hi));
}
}
Comments
Post a Comment