You are viewing a single comment's thread. Return to all comments →
Scanner sc = new Scanner(System.in); int A = sc.nextInt();
int[] array = new int[A]; for(int i = 0; i<A; i++) { array[i] = sc.nextInt(); } sc.close(); int negativeSubarrayCount = 0; for(int start = 0; start<A; start++) { int SubarraySum = 0; for(int end = start; end<A; end++) { SubarraySum += array[end]; if(SubarraySum<0) { negativeSubarrayCount++; } } } System.out.println(negativeSubarrayCount); }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Subarray
You are viewing a single comment's thread. Return to all comments →
Scanner sc = new Scanner(System.in); int A = sc.nextInt();
}****