Target Sum Pairs

I am pasting my code below, please let me know for which 1 test case is it failing:

import java.util.*;
public class Main {
public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    n = Math.abs(n);
    ArrayList<Integer> arr = new ArrayList<>();
    

    for(int i = 0; i<n; i++){
       if(sc.hasNextInt()) arr.add(sc.nextInt());
    }

    int target  = 0;
    if(sc.hasNextInt()) target = sc.nextInt();

    for(int i=0; i<arr.size();i++){
        
            if(arr.contains(target - arr.get(i))){
                if(arr.get(i)<=(target - arr.get(i)))
                System.out.println(arr.get(i) +" and "+ (target - arr.get(i)));
            }   
    }

}

}

@alisaban10_b6a0dfdcbf5cfeff You have to print pair increasing order.
for example : 5 and 6
not 6 and 5.

Thank you so much Piyush for taking out time. But I have used this condition for the same: if(arr.get(i)<=(target - arr.get(i))) System.out.println(arr.get(i) +" and "+ (target - arr.get(i)));

@alisaban10_b6a0dfdcbf5cfeff Debug your code for this input
5
5
2
3
4
1
6
Correct output :
1 and 5
2 and 4
Your output :
1 and 4
2 and 3

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.