Java Reference
In-Depth Information
// Experiment with overflow.
d *= 536870912;
y *= 536870912;
if (d == y) {
System.out.println ("Condition is true");
}
else {
System.out.println ("Condition is not true. d = " + d
+ " y = " + y);
}
Compile and rerun the HelloWorld application. The output should look
like this:
...
testMsg = ErrorMsg text
i = 5
z = 8
Condition is not true
Condition is true
Condition is not true. d = 2.147483648E9 y = -2147483648
Java specifies that integer multiplication will not cause an error condition
(exception) even if overflow occurs, so be careful with large integer num-
bers. Notice the way d is printed. Java double numbers are stored in IEEE
754 format, and this is a String representation of this format.
R EVIEWING THE E XERCISES
Let's review the samples you've created. Try to relate the sample source statements
to the result (that is, the output) each statement creates. If necessary, rerun the sam-
ples, or look at the complete source code for this exercise on the CD-ROM. Feel free
to experiment by yourself.
Java statements must end with a semicolon. A single statement can contain sev-
eral Java expressions.
Java uses parentheses to group expressions in much the same way that COBOL
does. Java's AND, OR, and NOT operators (&&, ||, !) work in much the same
way as do their COBOL counterparts.
Search WWH ::




Custom Search