come in
所在版块:社会百科 发贴时间:2003-08-27 23:16  评分:

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
1。what is i after the following for loop?
for (int i=0;i<10;++i){
y+=i;
}
为什莫答案是undefined?不应该是10吗?

>> i is only defined within the for loop structure

2。analyze the following fragment:
double sum=0;
double d=0;
while(d!=10.0){
d+=0.1;
sum+=sum+d;
}
答案:the program may not stop because of the phenomenon referred t as numerical inaccuracy for uperating with floating-pointing numbers.
为啥?不懂~~~~

>> floating number is represented in IEEE 754 standards, it means that for any number of float type in java, the system keeps only the first 23 bit after decimal point and thus there is some error in magnitude....just search on google use IEEE 754 to find out more details

3。analyze the following code:
boolean even=false;
if(even=true){
system.out.println(" it is even!");
}
写得有错吗?结果是什莫?

>>true is first assign to variable even, and then the value of variable even is evaluated (it's true by now).
>> = is not equivalent to == , the first one is assignment and the second is comparison....


4。even=number%2==0
有这种写法么? 是什莫意思呢?计算机看到这个expression后又是怎样工作的?

>> number % 2 == 0 is first evaluated, it may be true or false and this boolean value is then assigned to variable even. for additional knowledge check out "java operator precedence"
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

Put your OWN COOL signature here!
 相关帖子 我要回复↙ ↗回到正文
不好意思,还想问学长几个问题 tonymmm   (606 bytes , 678reads )
come in 想念老乡   (1304 bytes , 426reads )
for 2, more details here 想念老乡   (883 bytes , 541reads )
唔,第1,3,4题俺都懂了。谢谢学长.... tonymmm   (168 bytes , 292reads )
here 吴永铮   (206 bytes , 350reads )
但是对第一题 tonymmm   (53 bytes , 404reads )
看错了。loop完了i就不存在了。 吴永铮   (98 bytes , 242reads )