```
public int maxSubArray(int[] nums) {
int max=nums[0];
for(int i=0;i<nums.length;i++){
if (max < nums[i]) {
max = nums[i];
}
int sum=0;
for(int j=i;j<=nums.length-1;j++){
sum=sum+nums[j];
if (max < sum) {
max = sum;
}
}
}
return max;
}
```