Target sum pairs qes

import java.util.*;
public class sumpair {
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]);
			}
			}
		
		}
		}
	}}
}

It is not showing 100% this solution ?which test case i missed??

Hi @singhalharsh10081999

Your code doesn’t work for the case 5
5
2
3
4
1
6.
The output should be 1 and 5 , 2 and 4.

1 Like

Hi Harsh
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.