||

How can I initialize a double variable to infinity

纵然是瞬间 提交于 2020-02-29 19:44:59
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