我的一点想法
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 2 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:我心为谁动 (等级:3 - 略知一二,发帖:515) 发表:2003-08-27 23:42:16  楼主  关注此帖评分:
不好意思,还想问学长几个问题~~1。what is i after the following for loop? for (int i=0;i (more...)
我的一点想法
1. the three parts of for loop
part I: initialization
part II: governing condition (for the loop to continue)
part III: post condition, i.e. what's going to happen after each loop
however, ++i requires that increase i by 1 before entering a loop, this conflict with part III definition.

2. because the way float(double) numbers are represented in computer, u will find some floating point computing "wrong": 0.5 + 0.2 /= 0.7.

3. if (even==true)
in C, you can write if (var = somevalue), which will assign somevalue to var and return true, but in java, this is not allowed.

4. even = number%2==0 <==> even = (number%2==0)
sequence of actions taken by computer:
(1) computer number%2
(2) compare the previous result and 0 and return comparision result as a boolean value
(3) assign the boolean value to even.

其实每个问题都有想对应的理论(或者说术语)来解释的, 不过我一时间都想不起来是什么, 希望你大概明白吧。
如有纰漏,敬请各位更正。
Put your OWN COOL signature here!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:我心为谁动 (等级:3 - 略知一二,发帖:515) 发表:2003-08-28 00:12:40  2楼
我的一点想法1. the three parts of for loop part I: initialization part II: governing condition (for the loop to continue) part III: post condition, i.e. what's going to happen after each loop however, ++i requires that increase i by 1 before entering a loop, this conflict with part III definition. 2. because the way float(double) numbers are represented in computer, u will find some floating point computing "wrong": 0.5 + 0.2 /= 0.7. 3. if (even==true) in C, you can write if (var = somevalue), which will assign somevalue to var and return true, but in java, this is not allowed. 4. even = number%2==0 even = (number%2==0) sequence of actions taken by computer: (1) computer number%2 (2) compare the previous result and 0 and return comparision result as a boolean value (3) assign the boolean value to even. 其实每个问题都有想对应的理论(或者说术语)来解释的, 不过我一时间都想不起来是什么, 希望你大概明白吧。 如有纰漏,敬请各位更正。
第一个问题
我说错了,这样就没问题了
int i;
for (i=0; i<10; ++i) {
y += i;
}
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 2 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码