4.2.5
The
boolean
Type and
boolean
Values
TYPES, VALUES, AND VARIABLES
//
Another example of inexact results and rounding:
System.out.print("inexact results with double:");
for (int i = 0; i < 100; i++) {
double z = 1.0 / i;
if (z * i != 1.0)
System.out.print(" " + i);
}
System.out.println();
//
An example of cast to integer rounding:
System.out.print("cast to int rounds toward 0: ");
d = 12345.6;
System.out.println((int)d + " " + (int)( d));
}
}
produces the output:
overflow produces infinity: 1.0e+308*10==Infinity
gradual underflow: 3.141592653589793E 305
3.1415926535898E 310 3.141592653E 315 3.142E 320 0.0
0.0/0.0 is Not a Number: NaN
inexact results with float: 0 41 47 55 61 82 83 94 97
inexact results with double: 0 49 98
cast to int rounds toward 0: 12345 12345
This example demonstrates, among other things, that gradual underflow can
result in a gradual loss of precision.
The inexact results when
i
is
0
involve division by zero, so that
z
becomes
positive infinity, and
z * 0
is NaN, which is not equal to
1.0
.
4.2.5 The
boolean
Type and
boolean
Values
The
boolean
type represents a logical quantity with two possible values, indi
cated by the literals
true
and
false
( 3.10.3). The boolean operators are:
The relational operators
==
and
!=
( 15.20.2)
The logical complement operator
!
( 15.14.6)
The logical operators
&
,
^
, and
|
( 15.21.2)
The conditional and and conditional or operators
&&
( 15.22) and
||
( 15.23)
The conditional operator
? :
( 15.24)
The string concatenation operator
+
( 15.17.1), which, when given a
String
operand and a boolean operand, will convert the boolean operand to a
String
(either
"true"
or
"false"
), and then produce a newly created
String
that is
the concatenation of the two strings
36
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved