Java Reference
In-Depth Information
The Date constructor allows the program to request and store the current
system date at the time the program is executed. Once the variable currentDate
is constructed, it can be used in other parts of the program.
Formatting Output Using Escape Characters
In the Welcome to My Day program, you will insert special codes to indent
and position the output away from the left side of the screen. Java uses escape
characters inside the String arguments of the println() method to move the
insertion point to the right, which thereby moves the text output to the right.
Escape characters, also called escape codes or escape sequences, are non-printing
control codes. Table 2-8 displays some of the Java escape characters used to move
the output of data on a computer screen.
Table 2-8
Java Escape Characters
CODE
CONCEPT
RESULT
\t
horizontal tab
Moves insertion point eight spaces to the right.
\b
backspace
Moves insertion point one space to the left.
\n
new line
Moves insertion point down one line and to the left
margin.
\r
carriage return
Moves insertion point to the left margin.
Perform the following steps to edit the code to include escape characters that
position the text output.
To Code Escape Characters to Format Output
1. Click immediately to the left of the word, Welcome, in line 18.
The insertion point displays between the quotation mark and the W of
Welcome (Figure 2-38).
insertion
point
FIGURE 2-38
 
Search WWH ::




Custom Search