In: Computer Science
In Java, write a program that given an array A[1...n] and a value S finds 0 < i < j < n such that A[i] + A[j] = S
The snapshot of the output

// Java implementation using Hashing
import java.io.*;
import java.util.HashSet;
class PairSum {
   static void printpairs(int arr[], int sum)
   {
       HashSet<Integer> s = new
HashSet<Integer>();
       for (int i = 0; i < arr.length;
++i) {
           int temp = sum -
arr[i];
           // checking
for condition
           if
(s.contains(temp)) {
          
    System.out.println("Pair with given sum " + sum
+ " is (" + arr[i] + ", " + temp + ")");
           }
          
s.add(arr[i]);
       }
   }
   // Main to test the above function
   public static void main(String[] args)
   {
       int A[] = { 1, 4, 45, 6, 10, 8
};
       int n = 16;
       printpairs(A, n);
   }
}