How can I initialize a double variable to infinity
博客专区 > Oscarfff 的博客 > 博客详情
How can I initialize a double variable to infinity
Oscarfff 发表于3年前
How can I initialize a double variable to infinity
  • 发表于 3年前
  • 阅读 42
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】如何购买服务器最划算?>>>   

摘要: How can I initialize a double variable to infinity?

Q. How can I initialize a double variable to infinity?

A. Java has built-in constants available for this purpose: Double.POSITIVE_INFINITY

and Double.NEGATIVE_INFINITY.

Q. Can you compare a double to an int?

A. Not without doing a type conversion, but remember that Java usually does the requisite type conversion automatically. For example, if x is an int with the value 3, then

the expression (x < 3.1)  is true—Java converts x to double (because 3.1 is a double

literal) before performing the comparison.

Q. What are the values of 1/0 and 1.0/0.0 as Java expressions?

A. The first generates a runtime exception for division by zero (which stops your program because the value is undefined); the second has the value Infinity

Q. Why do we say (a && b) and not (a & b) ?

A. The operators &, | , and ^ are bitwise logical operations for integer types that do and,

or, and exclusive or (respectively) on each bit position. Thus the value of 10&6 is 14 and

the value of 10^6 is 12. We use these operators rarely (but occasionally) in this book.

The operators && and ||  are valid only in boolean expressions are included separately

because ofshort-circuiting: an expression is evaluated left-to-right and the evaluation

stops when the value is known.


标签: 1/0 and 1.0/0.0 && and ||
共有 人打赏支持
粉丝 70
博文 802
码字总数 96913
×
Oscarfff
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: