I don't know why it is showing array index out of bound exception
import java.util.*;
public class longLong {
public static void main(String []args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t != 0) {
int n = sc.nextInt();
int arr[] = new int[n];
int sum = 0;
int count = 1;
int j = 0;
for (int i = 0; i < n; i++){
arr[i] = sc.nextInt();
if (arr[i] < 0) {
sum = sum - arr[i];
} else sum = sum + arr[i];
}
for (int i = 0; i < n; i++) {
if (j < n) {
while (arr[j] <= 0) {
j = j + 1;
}
}
count = count + 1;
j = j + 1;
}
System.out.println(sum + " " + count);
t--;
}
}
}
I am trying to solve a question where a array of n size is given and we have to calculate sum of array and operations to be performed to make it positive array and the condition is we can invert only one sub array at a time