Java Reference
In-Depth Information
SR 2.5
What output is produced by the following code fragment?
System.out.print ("Ready ");
System.out.println ();
System.out.println ("Set ");
System.out.println ();
System.out.println ("Go ");
SR 2.6
What output is produced by the following statement? What is pro-
duced if the inner parentheses are removed?
System.out.println ("It is good to be " + (5 + 5));
SR 2.7
What is an escape sequence? Give some examples.
SR 2.8
Write a single println statement that will output the following exactly
as shown (including line breaks and quotation marks).
“I made this letter longer than usual because I lack the time to
make it short.”
Blaise Pascal
2.2 Variables and Assignment
Most of the information we manage in a program is represented by variables.
Let's examine how we declare and use them in a program.
Variables
A variable is a name for a location in memory used to hold a data
value. A variable declaration instructs the compiler to reserve a por-
tion of main memory space large enough to hold a particular type
of value and indicates the name by which we refer to that location.
Consider the program PianoKeys , shown in Listing 2.5. The first
line of the main method is the declaration of a variable named keys
that holds an integer ( int ) value. The declaration also gives keys an initial value
of 88. If an initial value is not specified for a variable, the value is undefined. Most
Java compilers give errors or warnings if you attempt to use a variable before
you've explicitly given it a value.
The keys variable, with its value, could be pictured as follows:
KEY CONCEPT
A variable is a name for a memory
location used to hold a value of a
particular data type.
keys
88
 
Search WWH ::




Custom Search