Target sum triplet( ist test case not pass)

can somebody check the code below and correct me where i am wrong.
package Arrays;

import java.util.Arrays;
import java.util.Scanner;

public class TripletSum {

public static void cal1(int[] arr, int sum) {
	Arrays.sort(arr);
	for (int i = 0; i < arr.length-1; i++) {
		
		int lo = i + 1;
		int hi = arr.length - 1;
		while (lo < hi) {
			if (arr[lo] + arr[hi] + arr[i] == sum) {
				System.out.println(arr[i] + ", " + arr[lo] + " and " + arr[hi]);
				lo++;
				hi--;
			} else if (arr[lo] + arr[hi] + arr[i] > sum) {
				hi--;
			} else if (arr[lo] + arr[hi] + arr[i] < sum) {
				lo++;
			}
		}
	}
}

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	if(n>1 && n<1000)
	{
	int[] arr = new int[n];
	for (int i = 0; i < n; i++) {
		arr[i] = scn.nextInt();
		
	}
	int target = scn.nextInt();
	cal1(arr, target);
	}
}

}

your code doesn’t handle the cases when there are duplicate elements.

i have already done that but getting same wrong answer.
can you suggest me the code for this?

you could do the following: Store the count of each number in a HashMap, and store just the distinct elements in the array and run your same program that you have just now. Now when you encounter a hit, extract the total number of times this triplet occurs as the product of occurrences of the three numbers and print the same triiplet this many number of times. This should be just a minor modification to your existing code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.