This is Discussion thread about Arrays-Target Sum Pairs
Discussion About Arrays-Target Sum Pairs
import java.util.*;
public class Main {
static Scanner scn = new Scanner(System.in);
public static void main(String args[]) {
int N = scn.nextInt();
int[] arr = new int[N];
takeInput(arr);
int target = scn.nextInt();
bubbleSort(arr);
targetSumPairs(arr, target);
}
public static void bubbleSort(int[] arr){
for(int i = 0; i < arr.length; i++ ){
for(int j = i + 1; j < arr.length - i; j++){
if(arr[i] > arr[j]){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
public static void targetSumPairs(int[] arr, int target){
for(int i = 0; i < arr.length - 1; i++){
for(int j = i + 1; j < arr.length; j++){
if(arr[i] + arr[j] == 5){
System.out.println(arr[i] + " and " + arr[j]);
}
}
}
}
public static void takeInput(int[] arr){
for(int i = 0; i < arr.length; i++){
arr[i] = scn.nextInt();
}
}
}
why my 2 test cases are failing ??