软件工程作业

1设计思路:

1自定义一个数组

2当数组数字依次相加,相加和小于零时再从下一个重新加

3输出和

2源程序代码

public class Test {

 

public static void main(String[] args) {

int n[] = { 10, -20, 60, -10, -30};

int zuida=0;

 

int temp=0;

 

 

for(int i=0;i<n.length;i++){

temp=n[i]+temp;

if(temp>zuida){

zuida=temp;

}

if(temp<0){

temp=0;

}

 

}

 

System.out.println(zuida);

 

}

 

}

3运行结果截图:

 

posted @ 2016-04-08 16:43  sunmei  阅读(87)  评论(0编辑  收藏  举报