Method class:
Package com.lwk.test2;
Import Java.util.Scanner;
public class Sum {
Scanner input = new Scanner (system.in);
public int sumparams (int nums[]) {
int maxsum = 0;
for (int i = 0; i < nums.length; i++) {
int sum = 0;
for (int j = i; J < Nums.length; J + +) {
sum = sum + nums[j];
if (Sum > Maxsum) {
Maxsum = sum;
}
}
}
System.out.println ("The maximum value of the sum of the Subarray is:" +maxsum);
return maxsum;
}
}
Test class:
Package com.lwk.test2;
Import static org.junit.assert.*;
Import Org.junit.Test;
public class Sumtest {
@Test
public void Test () {
/* int nums[] = {1,-2,3,5,-1}; *///test Case 1 Maximum value 8
/* int nums[] = {1,-2,3,-8,5,1}; *///test Case 1 Maximum value 6
int nums[] = {1,-2, 3,-2, 5, 1}; Test Case 1 Maximum value 7
Sum sum = new sum ();
Sum.sumparams (Nums);
}
}
There are three test cases, you can add different test cases according to your needs
Practice numerical calculations. Find the maximum value of the sum of the neutron arrays of an integer array.