come in
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"
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"