import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static int sumofAllSubarrays(int [] arr){
int n = arr.length;
int sum = arr[0];
int maxSum = Integer.MIN_VALUE;
for(int i=1 ; i<n ; i++){
if(sum < 0 ){
sum = 0 ;
}
sum += arr[i];
if(sum > maxSum){
maxSum = sum ;
}
}
return maxSum;
}
public static void main(String[] args) {
int [] arr = {1, -3, 2, 1, -1, 6, -2, 4};
System.out.println("Result " + sumofAllSubarrays(arr));
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: