title: kadane algorithm in java
body: <p>I have the following implementation of Kadane's algorithm in java. It is basically to find the maximum sum of contiguous subarray.</p>
  
  <pre><code>String[] numbers = string.split(",");
                  int max_so_far = 0;
                  int max_ending_here = 0;
                  for (int i = 0; i &lt; numbers.length-1;i++){
                       max_ending_here = max_ending_here + Integer.parseInt(numbers[i]);
                       if (max_ending_here &lt; 0)
                           max_ending_here = 0;
                       if (max_so_far &lt; max_ending_here)
                            max_so_far = max_ending_here;
                  }
                  System.out.println(max_so_far);
  </code></pre>
  
  <p>However this doesn't work if there is a combination of a negative and positive number in an array, for example the following:</p>
  
  <pre><code>2,3,-2,-1,10
  </code></pre>
  
  <p>Which should return a 12 as a maximum. As of now it returns 5</p>