4rth test case not passing in online ide

getting correct solution when running code on local eclipse ide. but not 4th test case is failing in online ide.
here is code:
import java.util.*;
public class PairSumInArray{

static void pairSum(List<Integer> ar,int n,int sum){
	int l = 0;
	int r = n-1;
	while(l<=r){
		if(ar.get(l)+ar.get(r)==sum){
			System.out.println(ar.get(l)+" and "+ar.get(r));
			l++;
		}else if(ar.get(l)+ar.get(r)<sum){
			l++;
		}else{
			r--;
		}
	}
}


public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	List<Integer> ar = new ArrayList<>();
	for(int i=0;i<n;i++){
		ar.add(sc.nextInt());
	}
	int sum = sc.nextInt();
	Collections.sort(ar);
	pairSum(ar,n, sum);
}

}

@adarshkumar4145
import java.util.*;
public class Main{

static void pairSum(List ar,int n,int sum){
int l = 0;
int r = n-1;
while(l<r){
if(ar.get(l)+ar.get®==sum){
System.out.println(ar.get(l)+" and "+ar.get®);
l++;

	}else if(ar.get(l)+ar.get(r)<sum){
		l++;
	}else{
		r--;
	}
}

}

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List ar = new ArrayList<>();
for(int i=0;i<n;i++){
ar.add(sc.nextInt());
}
int sum = sc.nextInt();
Collections.sort(ar);
pairSum(ar,n, sum);
}
}

here is correct code.
the condition has to be while(l<r)

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.