one of my test case not run where is the problem in my code
Target sum Pair
import java.util.Scanner;
public class SumPairHint {
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 t = sc.nextInt();
bubbleSort(arr);
sum(arr, t);
}
public static void bubbleSort(int[] arr) {
for (int counter = 0; counter < arr.length - 1; counter++) {
for (int j = 0; j < arr.length - 1 - counter; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
public static void sum(int[] arr, int t) {
int l = 0;
int r = arr.length - 1;
while (l < r) {
int ans = arr[l] + arr[r];
if (ans > t) {
r--;
} else if (ans == t) {
System.out.println(arr[l] + " and " + arr[r]);
r--;
l++;
}
}
}
}
this is my code one test case not run
@Amre-8800,
https://ide.codingblocks.com/s/239467 corrected code
I have commented and corrected the errors in your code.