Although the algorithm written is very poor, but I will not be talking about it. :)
Just the thing that, you can have the function print that the values in the array do not sum to the value provided, inside the function itself, if the iterations have finished running. Like this,
public static void arri(int arr[],int n)
{
int first=0,second=0;
for(int a=0;a<arr.length;a++) {
first=arr[a];
for(int b=a+1;b<arr.length;b++) {
second=arr[b];
if(first + second == n) {
System.out.printf("(%d, %d)%n", first, second);
return;
}
}
}
System.out.println("no such pairs exist");
}
Tip: You can improve the function by using a different approach, for example, use one index and follow along the start of the array, and sum it with the last element in the array to see if you got it. This would work with sorted arrays. In the case of an unsorted one, you can try saving the numbers you have seen and finding it you have that number available in the previous list. This will improve the current algorithm from O(N
2) to O(N).
In academics, data structures, algorithms and refinement matter a lot, please do not skip them, otherwise getting a job will be more difficult than this simple problem. :-) Just my 2 cents.