当前位置: 代码迷 >> Java相关 >> 麻烦帮我解释一下
  详细解决方案

麻烦帮我解释一下

热度:396   发布时间:2004-08-28 18:59:00.0
麻烦帮我解释一下

what will happen when you attempt to compile and run the following code?

(assume that the code is compiled and run with assertions enabled)

public class AssertTest

{

public static void main(String args[])

{

float f1 = Float.NaN;

float f2 = f1;

float f3 = 1.2f;

try

{

assert(f2 == f1):f2= 2;

f3 = 1.5f;

}catch(AssertionError ae)

{

f3++;

}

f3 += f2;

System.out.println("f3 = " + f3);

}

}

A. compilation error at line 5

B.compilation error at line 7

C.It will print- f3 = 3.5

D.It will print- f3 = 4.2

E.It will print- f3 = NaN

在上面的assert(f2 == f1) : f2 = 2;中间的:不明白是什么意思。怎么解释这句话?还有NaN是什么意思?在做题碰到好多这样的题,好郁闷。。。。。麻烦高手帮帮忙解释一下,谢谢

搜索更多相关的解决方案: 麻烦  解释  

----------------解决方案--------------------------------------------------------

NaN stands for Not a Number, 从jdk API可以查到,在float class里面

assertion,断言,在jdk1。4引入,一种新的异常处理机制,哦,应该是更高级的一种,具体网上去查吧。不过我几乎没有用到过,也许我还没有到那种程度,呵呵


----------------解决方案--------------------------------------------------------