SortGame code ,Whats the problem in this approach?

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class SortGame {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int x=s.nextInt();
int n=s.nextInt();
ArrayList list1=new ArrayList<>();
ArrayList list2=new ArrayList<>();
for(int i=0;i<n;i++) {
list1.add(i,s.next());
list2.add(i,s.nextInt());
}
for(int i=0;i<n-1;i++) {
for(int j=i+1;j<n;j++) {
if(list2.get(i)<list2.get(j)) {
Collections.swap(list2, i, j);
Collections.swap(list1, i, j);
}
else if(list2.get(i)==list2.get(j)) {
if(list2.get(i)<list2.get(j)) {
Collections.swap(list2, i, j);
}
}
}
}
for(int i=0;i<n;i++){
if(list2.get(i)>x) {
System.out.println(list1.get(i)+" "+list2.get(i));
}
}
}
}

make use of classes and objects to solve this ques…for sorting write your own compereTo function(implement comparable interface)

in your case in the else if block of sort function you should write logic for comparing lexicographically

also first save your code on ide.codingblocks.com and then share the link here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.