import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class Emplyee
{
String name;
int salary;
public Emplyee(String name,int salary)
{
this.name=name;
this.salary=salary;
}
}
class SortbySalary implements Comparator
{
@Override
public int compare(Emplyee o1, Emplyee o2) {
return o2.salary-o1.salary;
}
}
public class SortGame {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int max=sc.nextInt();
int n=sc.nextInt();
Emplyee a[]=new Emplyee[n];
for(int i=0;i<n;i++)
{
String name=sc.next();
int salary=sc.nextInt();
Emplyee e=new Emplyee(name, salary);
a[i]=e;
}
Arrays.sort(a,new SortbySalary());
int sum=0;
for(int i=0;i<n;i++)
{
if(a[i].salary>=max)
{
if(i+1<n&&a[i].salary==a[i+1].salary)
{
if(a[i].name.compareTo(a[i+1].name)<0)
{
System.out.println(a[i].name+" "+a[i].salary);
System.out.println(a[i+1].name+" "+a[i+1].salary);
}
else
{
System.out.println(a[i+1].name+" "+a[i+1].salary);
System.out.println(a[i].name+" "+a[i].salary);
}
i++;
}
else
{
System.out.println(a[i].name+" "+a[i].salary);
}
}
}
}
}
what is the problem with this code
it is showing no such elemnt exception