标签:oid style max com string span i++ system col
package wodeshiyao; import java.util.Scanner; public class lalala { static Scanner scan=new Scanner(System.in); public static void main(String[] args) { // TODO Auto-generated method stub int b; System.out.println("请输入数组长度:"); b=scan.nextInt(); int a[]=new int [b];//定义规定长度的整型数组 System.out.println("请输入数组元素:"); for(int i=0;i<b;i++) { a[i]=scan.nextInt(); } int i,j,k; int max[]=new int [b]; for(i=0;i<b;i++){ max[i]=a[i]; k=a[i]; for(j=i+1;j<b;j++){ k=k+a[j]; if(k>max[i]) {max[i]=k;} } } int m=max[0]; for(i=1;i<b;i++) { if(max[i]>m) {m=max[i];} } System.out.println("所有连续子数组和的最大值为:"+m); } }
结果如图
标签:oid style max com string span i++ system col
原文地址:https://www.cnblogs.com/jmdd/p/10506719.html