标题:麻烦帮我解释一下
只看楼主
pine
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2004-8-10
 问题点数:0 回复次数:1 
麻烦帮我解释一下

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是什么意思?在做题碰到好多这样的题,好郁闷。。。。。麻烦高手帮帮忙解释一下,谢谢

搜索更多相关主题的帖子: 麻烦 解释 
2004-08-28 18:59
tailys
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2004-8-16
得分:0 

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

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

2004-08-30 01:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-4669-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.567263 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved