public void getMaxArray(int[] a) { int start = 0; int end = 0; int currentSum = 0; int maxSum = Integer.MIN_VALUE; int aStart = 0; for (int i = 0; i < a.length; i++) { currentSum += a[i]; if (a[i] > currentSum) { currentSum = a[i]; aStart = i; } if (currentSum > maxSum) { maxSum = currentSum; start = aStart; end = i; } } System.out.println("maxSum:" + maxSum + ",a[" + start + "]" + ",a[" + end + "]"); }