I'm stuck in this code half of the logic i implemented pls help

public class App14_TargetSumTriplets {

static void targetSumTriplet(int[] arr, int target) {
	int low = 0;
	int high = arr.length - 1;
	int mid = (low + high) / 2;
	
	while (low < high) {

		if (arr[low] + arr[mid] + arr[high] == target) {
			System.out.println(arr[low] + " " + arr[mid] + " " + arr[high]);
			low++;
			mid++;
		} else if (arr[low] + arr[mid] + arr[high] > target) {
			mid--;
			high--;
		} else {
			high++;
		}

	}
}

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();

	int[] arr = new int[N];

	for (int i = 0; i < arr.length; i++) {
		arr[i] = sc.nextInt();
	}
	int target = sc.nextInt();
	Arrays.sort(arr);
	targetSumTriplet(arr, target);
}

}

pls help me im waiting

@nigamshubham1998,
Algorithm:

1.Sort the element in ascending order

  1. Start a loop from i=0 to i<n. We mark arr[i] at each instance as a fixed element for that iteration and work to find a pair of elements such that their sum is equal to target-arr[i] hence ensuring that the net sum of the three elements would be equal to target.
  2. Inside this loop, implement the two pointer approach. Keep a left pointer starting from i+1 and a right pointer from n-1.
  3. Work an inner left till left<right. For each iteration , check whether a[i] + a[left] + a[right] == target. If so ,print the triplet. Else if this sum = a[i] + a[left] + a[right] is less than the target , then increment the left pointer by one. Else decrement the right pointer by one.

3.Thus, all the triplets have been printed.

You don’t have to take mid. Just take low and high and iterate the array using a for loop

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.