//Given an array arr[N],, check if any pair (i,j) exist such that arr[i] + arr[j]==K , and i!=j;Count these kind of pair 

import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {

    public static int countPairSum(int [] arr , int k ){
        int count = 0;
        int n = arr.length;
        for(int i=0; i<n; i++){
            for(int j=i+1 ; j<n ; j++){
                if(arr[i] + arr[j] == k){
                    count++;
                }
            }
        }
        return count ;
    }
    
    public static void main(String[] args) {
        int arr[] = {2, 5 , 2 , 5 , 8 , 5 , 2 , 8 };
        int k = 10;
        
        System.out.println("Final Count " + countPairSum(arr,k));
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: