java算法,高手请进!

liqianghunnueducn 2007-06-29 05:32:14
分析:
语句一:for(int i=0,j=0;j<a.length;j++)
语句二else if(thisSum<0){
i=j+1;}


请分析语句一二的联系与关系,主要是逗号表达式的含义不太明白

谢谢!


public class t {

static int start=0;
static int end=0;

public static int maxSeq(int[] a){
int maxSum=0;
int thisSum=0;

for(int i=0,j=0;j<a.length;j++){
thisSum+=a[j];
if(thisSum>maxSum){
maxSum=thisSum;
start=i;
end=j;
}
else if(thisSum<0){
i=j+1;
thisSum=0;
}
}
return maxSum;
}

public static void main(String agr[]){
int[] b={3,1,-1,6,1,3};
int temp=t.maxSeq(b);
System.out.println(temp);
System.out.println(t.start);
System.out.println(t.end);
}
}
...全文
169 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dracularking 2007-06-29
  • 打赏
  • 举报
回复
逗号表达式不就是并列存在嘛

i只是在for循环的作用域内定义了而已

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧