You are viewing a single comment's thread. Return to all comments →
public static void main(String[] args) { Scanner in = new Scanner(System.in); int largo_array = in.nextInt(); int array[] = new int[largo_array];
for(int i = 0; i < largo_array; i++){ array[i] = in.nextInt(); } in.close(); int count = 0; int suma; for(int j = 0; j < largo_array; j++){ suma = array[j]; if(suma < 0){ count++; } for(int k = j + 1; k < largo_array; k++){ suma+= array[k]; if(suma < 0){ count++; } } } System.out.println(count); }
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 →
public static void main(String[] args) { Scanner in = new Scanner(System.in); int largo_array = in.nextInt(); int array[] = new int[largo_array];