java中a的值多少_关于在Java中 a!=a 值为真的解释

In java spec , the primitive type is implemented in a certain defined way. The floating-types are implemented in IEEE-754 standard. Ref from java spec: The IEEE 754 standard includes not only positive and negative sign-magnitude numbers, but also positive and negative zeros, positive and negative infinities, and a special _Not-a-Number _value (hereafter abbreviated as “NaN”). The NaN value is used to represent the result of certain invalid operations such as dividing zero by zero. So, in this case , java specified that a!=a is true if the variable is NaN. So does the case i present yesterday (a=b) if either a or b is NaN. Now I wil give you a example show it: ……… double a=0; double b=0; a=a/b; if(a!=a) System.out.println(“OK, a!=a is true!"); if((a=b)) System.out.println(”……..");

But I think the problem is a little tricky, If you have not yet read something from the java spec or something other, you will not  know that. But when the problem been proposed to us ,we should think about the problem in a logical way ,but not the way coding it to see if a=0, and then  a!=a is false. What i want to see is not the result of this ,but the thinking way of the job seeker.

.net 2.0里面也是这样

Module Test Sub Main() Dim a as double=0 Dim b as double=0 a=a/b console.writeline(“a ={0}",a) console.writeline(“a<>a ={0}",a<>a) console.writeline(“a=a ={0}",a=a) console.writeline(“ab ={0}",a>b) console.writeline(“a=b ={0}",a=b) End Sub end module

结果: a =非数字 a<>a =True a=a =False ab =False a=b =False

本文同步分享在 博客“贺思聪”(other)。

如有侵权,请联系 support@oschina.cn 删除。

本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值