@@ -0,0 +1,1495 @@
+package java_problems.data_structures;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * You are given an array of n integers. A sub-array is %22Negative%22 if sum of%0D%0A * all the integers in that sub-array is negative. Count the number of%0D%0A * %22Negative sub-arrays%22 in the input array.%0D%0A * %0D%0A * Note: Subarrays are contiguous chunks of the main array. For example if the%0D%0A * array is %7B1,2,3,5%7D then some of the subarrays are %7B1%7D, %7B1,2,3%7D, %7B2,3,5%7D,%0D%0A * %7B1,2,3,5%7D etc. But %7B1,2,5%7D is not an subarray as it is not contiguous.%0D%0A * %0D%0A * Input Format: %0D%0A * The first line consists an integer n. The next line will contain n space%0D%0A * seperated integers. Value of n will be at most 100. The numbers in the array%0D%0A * will range between -10000 to 10000.%0D%0A * %0D%0A * Output Format: %0D%0A * Print the answer to the problem.%0D%0A * %0D%0A * Sample Input:%0D%0A * 5%0D%0A * 1 -2 4 -5 1%0D%0A */%0D%0Apublic class OneDimensionalArray %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09Scanner sc = new Scanner(System.in);%0D%0A%09%09System.out.println(%22Enter positive number of integers to follow: %22);%0D%0A%09%09int n = sc.nextInt();%0D%0A%09%09System.out.println(%22Enter %22%0D%0A%09%09%09+ n + (n %3E 1 ? %22 integers: %22 : %22 integer: %22));%0D%0A%09%09int%5B%5D array = new int%5Bn%5D;%0D%0A%09%09for (int i = 0; i %3C array.length; i++) %7B%0D%0A%09%09%09array%5Bi%5D = sc.nextInt();%0D%0A%09%09%7D%0D%0A%09%09int numNeg = 0;%0D%0A%09%09for (int j = 0; j %3C array.length; j++) %7B%0D%0A%09%09%09int sum = 0;%0D%0A%09%09%09for (int k = j; k %3C array.length; k++) %7B%0D%0A%09%09%09%09sum += array%5Bk%5D;%0D%0A%09%09%09%09if (sum %3C 0) %7B%0D%0A%09%09%09%09%09numNeg++;%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09System.out.println(numNeg);%0D%0A%09%09sc.close();%0D%0A%09%7D%0D%0A%7D

Add OneDimensionalArray