Java Reference
In-Depth Information
SR 2.33
During the execution of the statement, the value stored in value is read
and transformed into a float as it is being copied into the memory
location represented by result . But the value variable itself is not
changed, so value will remain an int variable after the assignment
statement.
SR 2.34
During the execution of the statement, the value stored in result is read
and then transformed into an int as it is being copied into the memory
location represented by value . But the result variable itself is not
changed, so it remains equal to 27.32, whereas value becomes 27.
SR 2.35
The results stored are
a. 3
integer division is used since both operands are integers.
b. 3.0
integer division is used since both operands are integers,
but then assignment conversion converts the result of 3
to 3.0.
c. 2.4
floating point division is used since one of the operands is
a floating point.
d. 3.4
num1 is first cast as a double ; therefore, floating point divi-
sion is used since one of the operands is a floating point.
e. 2
val1 is first cast as an int ; therefore, integer division is
used since both operands are integers.
2.6 Interactive Programs
SR 2.36
The corresponding lines of the GasMileage program are
a. import java.util.Scanner ;
b. Scanner scan = new Scanner (System.in) ;
c. Scanner scan = new Scanner (System.in);
d. miles = scan.nextInt();
SR 2.37
Under the stated assumptions, the following code will ask users to enter
their age and store their response in value.
System.out.print ("Enter your age in years: ");
value = myScanner.nextInt();
2.7 Graphics
SR 2.38
A black and white picture can be drawn using a series of dots, called
pixels. Pixels that correspond to a value of 0 are displayed in white, and
pixels that correspond to a value of 1 are displayed in black. By using
Search WWH ::




Custom Search