Java Reference
In-Depth Information
SR 2.6
The output produced by the statement is
It is good to be 10
The + operator in the sub-expression (5 + 5) represents integer addi-
tion, since both of its operands are integers. If the inner parentheses
are removed, the + operators represent string concatenation and the
output produced is
It is good to be 55
SR 2.7
An escape sequence is a series of characters that begins with the backs-
lash ( \ ) and that implies that the following characters should be treated
in some special way. Examples: \n represents the newline character, \t
represents the tab character, and \" represents the quotation character
(as opposed to using it to terminate a string).
SR 2.8
System.out.println ("\"I made this letter longer than "
+ "usual because I lack the time to\nmake it short.\""
+ "\n\tBlaise Pascal");
2.2 Variables and Assignment
SR 2.9
A variable declaration establishes the name of a variable and the type
of data that it can contain. A declaration may also have an optional
initialization, which gives the variable an initial value.
SR 2.10
Given those variable declarations, the answers are:
a. Five variables are declared: count , value , total , MAX_VALUE , and
myValue .
b. They are all of type int .
c. count, MAX_VALUE , and myValue are each given an initial value.
d. Yes, it is legal. myValue is a variable of type int and 100 is an int
literal.
e. No, it is not legal. MAX_VALUE is declared as a final variable and
therefore it cannot be assigned a value other than its initial value.
SR 2.11
The variable name you choose should reflect the purpose of the variable.
For example:
int numCDs = 0;
SR 2.12
The variable name you choose should reflect the purpose of the variable.
Since the number of feet in a mile will not change, it is a good idea to
declare a constant. For example:
final int FT_PER_MILE = 5280;
Search WWH ::




Custom Search