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);
}
}
}