Target sum pairs

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner (System.in);
int n=scn.nextInt();
if(n>=1&&n<1000) {
int []har=new int[n];
for(int j=0;j<n;j++)
{
har[j]=scn.nextInt();
}
int target=scn.nextInt();
int []sd=sort(har);
sumpairs(sd,target);
}

}
public static int[] sort(int []arr) {
for(int k=0;k<arr.length-1;k++)
{
for(int l=0;l<arr.length-1-k;l++)
{
if(arr[l]>arr[l+1])
{
int temp=arr[l];
arr[l]=arr[l+1];
arr[l+1]=temp;
}
}

}
return arr;

}
public static void sumpairs(int []arr,int i)
{
int r=0;
int t=0;
{
for(r=0;r<arr.length;r++)
{
for(t=0;t<arr.length;t++)
{
if(arr[r]<=arr[t])
{
if(i==(arr[r]+arr[t]))
{
System.out.println(arr[r]+" and "+arr[t]);
}
}

	}
	}
}}

}
out of 4 testcases only one showing error so code was not submitted.can u tell where i went wrong

@karthik1989photos,

input:
6
1
2
3
3
4
5
6

Your output:
1 and 5
2 and 4
3 and 3
3 and 3
3 and 3
3 and 3

Correct output:
1 and 5
2 and 4
3 and 3

Suggested approach:
1.First sort the given array.
2.Now take two variables one as left and other as right starting from 0th and end index of the sorted array respectively.
3.Now iterate till left<right.

        3.1 Calculate the sum of the elements at left and right position  
        3.1.1 If the sum is equal to the target then print both the elements. //printing target sum pairs  
        3.1.2 If the sum is less than the target then increase the left by 1  
        3.1.3 Else decrease the right by 1  

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.