public class Test1 { public static void main(String[] args) { int[] arr = new int[]{1,3,3,-1,-5,3,7,-10}; int max = arr[0]; int sum = 0; for(int i=0; i<arr.length; i++) { sum += arr[i]; if(sum < 0) { sum = 0; } if(sum > max) { max = sum; } } System.out.println("Max:" + max); } }