Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 不理解的bug。(if)
develop8





发贴: 129
积分: 0
于 2006-06-23 07:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
/*在一回循环结束之后,
为什么 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}


why edited on 2006-06-23 21:14

作者 Re:不理解的bug。(if) [Re:develop8]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-06-23 09:45 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
分析?
Why don't you use your debugger to trace the execution?



作者 Re:不理解的bug。(if) [Re:why]
lisliefor





发贴: 287
积分: 7
于 2006-06-23 19:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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!意思表达确实不大明白。



作者 Re:不理解的bug。(if) [Re:develop8]
lisliefor





发贴: 287
积分: 7
于 2006-06-23 19:11 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
why edited on 2006-06-23 09:19

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



作者 Re:不理解的bug。(if) [Re:develop8]
develop8





发贴: 129
积分: 0
于 2006-06-24 06:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我没用过 debugger,所以,不会啊。能给我简单的说明,degugger吗
怎么使用,用他能看出什么来啊????




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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