Print the number of subarrays in an array having negative sum : <pre><code>import java.io.*;
import java.util.*;
public class Solution {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt(); //taking input number of elements in the array
        int[] a=new int[n];
        for(int i=0;i&lt;n;i++){
            a[i]=scan.nextInt(); //taking input elements of the array
        }
        int count=0;
        //start point
        for(int i=0;i&lt;n;i++){
            //end point
            for(int j=i;j&lt;n;j++){
                for(int k=i;k&lt;=j;k++){
                    int sum=0;
                    sum+=a[k];  //calculating the sum of subarray
                    if(sum&lt;0)
                    count++;
                }
            }
        }
        System.out.println(count); //printing the no of negative sums 
    }
}
</code></pre>

<p>Here there are three nested loops first loop defines the starting position second loop defines the ending position and third loop is for iterating over the elements of the subsrray and calculating their sums and if the sum is less than zero then increment the count.But with this code I am getting wrong answer.</p>
