源代码如下:
package classone;import java.util.Scanner;public class Test { static int number=50; static int[] t1 = new int[number]; static int[] t2 = new int[number]; //从第几个开始子数组 static int[] t3 = new int[number]; //从第几个开始子数组之和 static int[] t4 = new int[number]; //从第几个开始子数组 static int[] t5 = new int[number]; static int[] t6 = new int[number]; //从第几个开始子数组 static int[] t7 = new int[number]; static int[] t8 = new int[number]; public static void input() { t1[0]=0;t2[0]=0;t3[0]=0; System.out.println("输数字数量:"); Scanner input=new Scanner(System.in); number=input.nextInt(); for(int i=1;i<=number;i++) { int a=(int)(Math.random()*2+1); int aa=(int)(Math.pow(-1, a)); System.out.println(aa); int aaa=(int)(Math.random()*100+1); int b=aa*aaa; t1[i]=b; } System.out.println("T1数组:"); for(int i=1;i<=number;i++){ System.out.print("["+t1[i]+"]"); } } //输入数组 public static void vs() { int max=0;//比较 int b=t1[1]; int count=0; int single; int single1; int icount=0; int jcount=0; int sum=0; for(int i=1;i<=number;i++) { icount++; //记录I执行次数 int num=0; //当前数组之和 for(int j=i;j<=number;j++) { count++; //计数比较了多少给数组 jcount++; //记录J执行次数 num+=t1[j]; //当前数组之和 t2[j]=num; //t2存储当前数组之和 t2[0]=t2[1]; for(int s=1;s<=number;s++) { max=t2[j-1]; if(maxicount) { count=single1-1; j=single1-icount; num=0; for(int q=i;q<=j;q++) { num+=t1[i]; } }else if(single1
结果