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.
来源:oschina
链接:https://my.oschina.net/u/2308739/blog/464506