If the array is {-1 3 -1 9 4 -4}. I want the output as
"The sum is 15 and the array is {3 -1 9 4}."
I have the code for the sum, but how to go about for getting this subarray?
here is the code for the sum
int maxSum = 0, thisSum = 0;
for( int j = 0; j < a.length; j++ ){
thisSum += a[ j ];
if( thisSum > maxSum ){
maxSum = thisSum;
}
else if( thisSum < 0 )
thisSum = 0;
}
System.out.println( maxSum );
maxStart(based onj) when you updatemaxSum(and possibly amaxEnd).