Topic: 不理解的bug。(if)

  Print this page

1.不理解的bug。(if) Copy to clipboard
Posted by: develop8
Posted on: 2006-06-23 07:39

/*在一回循环结束之后,
为什么 int k=10*( count+1 );在if 语句里头 就执行,在else语句里头就没执行?
但你输入20,30,。。的时候他因为没有执行上面的语句所以,退出了循环。
到底是不理解啊,请读者帮我分析一下吧。
*/

class test{
public static void main(String[]args){
int x=Integer.parseInt(args[0]);
int count=0;
int count2;
if(x%10!=0){
count2=x/10+1;
int k=10*( count+1 );
for(int i=count*10;i<=k;i++){
System.out.println(i);
System.out.println("---");
count++;
if(count==count2)
k=x;
if(i>x)break;
}
}
else{
int k=10*( count+1 );
for(int i=count*10;i<=k;i++){
System.out.println(i);
System.out.println("---");
count++;
if(i==x)
break;
}
}

} // end of main.
}



{ Please try to format your code properly. And use [code ] tag as well as check "Disable Smileys" -- why}

2.Re:不理解的bug。(if) [Re: develop8] Copy to clipboard
Posted by: why
Posted on: 2006-06-23 09:45

分析?
Why don't you use your debugger to trace the execution?

3.Re:不理解的bug。(if) [Re: why] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-06-23 19:09

why wrote:
分析?
Why don't you use your debugger to trace the execution?

请仔细看楼主的问题!

我们从分析算法逻辑开始,当输入数为20,那么程序进入else{....}块。
这时候,k= 10*(0+1) = 10
x = 20
for(int i = 0;i<=10;i++)
输出:0
---
count = 1
i = 1;
第二次循环....
运行结果为:
0
---
1
---
2
---
3
---
4
---
5
---
6
---
7
---
8
---
9
---
10
---

请问楼主还有什么疑问么?
我也看不大明白你的疑问哦!表怪why!意思表达确实不大明白。

4.Re:不理解的bug。(if) [Re: develop8] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-06-23 19:11

why edited on 2006-06-23 09:19

我对这句话比较感兴趣!向why致意!
每个帖子都有哦~
辛苦了!

5.Re:不理解的bug。(if) [Re: develop8] Copy to clipboard
Posted by: develop8
Posted on: 2006-06-24 06:39

我没用过 debugger,所以,不会啊。能给我简单的说明,degugger吗
怎么使用,用他能看出什么来啊????


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923