Here you can find the source of maxSum(int[] array)
public static int maxSum(int[] array)
//package com.java2s; //License from project: Open Source License public class Main { public static int maxSum(int[] array) { if (array == null || array.length == 0) { return 0; }/* w w w .j a v a 2s. c o m*/ int maxEndIndex = 0; int maxSum = 0; int length = array.length; for (int i = 0; i < length; i++) { maxEndIndex = Math.max(maxEndIndex + array[i], 0); maxSum = Math.max(maxSum, maxEndIndex); } return maxSum; } public static long maxSum(long[] array) { if (array == null || array.length == 0) { return 0; } long maxEndIndex = 0; long maxSum = 0; int length = array.length; for (int i = 0; i < length; i++) { maxEndIndex = Math.max(maxEndIndex + array[i], 0); maxSum = Math.max(maxSum, maxEndIndex); } return maxSum; } public static float maxSum(float[] array) { if (array == null || array.length == 0) { return 0; } float maxEndIndex = 0; float maxSum = 0; int length = array.length; for (int i = 0; i < length; i++) { maxEndIndex = Math.max(maxEndIndex + array[i], 0); maxSum = Math.max(maxSum, maxEndIndex); } return maxSum; } public static double maxSum(double[] array) { if (array == null || array.length == 0) { return 0; } double maxEndIndex = 0; double maxSum = 0; int length = array.length; for (int i = 0; i < length; i++) { maxEndIndex = Math.max(maxEndIndex + array[i], 0); maxSum = Math.max(maxSum, maxEndIndex); } return maxSum; } }