Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Find pairs in an array that sum to y

Go down

Find pairs in an array that sum to y Empty Find pairs in an array that sum to y

Post  Admin Mon Aug 29, 2011 11:00 pm

public static void FindPair(int[] arr, int y){
arr=Array.sort(arr);
int len=arr.length();
int j=len-1;
while(i<j){
int sum=arr[i]+arr[j];
if(y==sum){
System.out.println("A pair: "+ arr[i]+" and "+arr[j]);
i++;
j--;
}
else if(sum>y)
j--;
else
i++;
}
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum