My program for the coding challenge produces the correct output, however, it requires me to press enter a second time for it to work. Here is the programming challenge.
It prints out the first line just fine but requires me to press enter again for it to work.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
sc.nextLine();
for(int i = 0; i < testCases; i++){
int size = sc.nextInt();
sc.nextLine();
int[] arr = new int[size];
for(int x = 0; x < size; x++){
arr[x] = sc.nextInt();
}
sc.nextLine();
if(size > 1){
solve(arr);
}
else{
System.out.println("0");
}
}
}
private static void solve(int[] arr) {
for(int i =0 ; i < arr.length; i++){
arr[i] = Math.abs(arr[i]);
}
Arrays.sort(arr);
for(int i = 0; i < arr.length - 1; i++){
int f = i + 1;
if(arr[i] == arr[f]){
System.out.print((arr[i] * -1) + " " + arr[i]);
}
}
System.out.println();
}
}