How can I initialize a double variable to infinity

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

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

and Double.NEGATIVE_INFINITY.this

Q. Can you compare a double to an int?lua

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, thenspa

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

literal) before performing the comparison.ci

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

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 Infinityit

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

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.

相關文章
相關標籤/搜索