Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

/******************************************************************************

Online Java Compiler.

Code, Compile, Run and Debug java program online.

Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.util.*;

class Employee

String name;

int age;

Employee(String name,int age)

this.name=name;

this.age=age;

public class Main

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

Employee[] e=new Employee[n];

for(int i=0;i<n;i++)

String name1=sc.nextLine();

sc.nextLine();

int age1=sc.nextInt();

e[i]=new Employee(name1,age1);

}
Employee e1=secondLargestAge(e);

System.out.println(e1.name+"-->"+e1.age);

public static Employee secondLargestAge(Employee[] e)

{ Employee e1;

int max1=e[0].age;

int max2=max1;

e1=e[0];

for(int i=0;i<e.length;i++)

if(e[i].age>max1)

max2=max1;

max1=e[i].age;

for (int i=0;i<e.length;i++)

if(max2==e[i].age)

e1=e[i];

break;

return e1;

}
}

You might also like