Java Reference
In-Depth Information
On the screen, the insertion point is where the cursor is.
2
In an output statement, if expression consists of only one string or a single constant
value, then expression evaluates to itself. If expression consists of only one variable,
then expression evaluates to the value of the variable. Also note, as explained in this
chapter, how the operator + works with strings and numeric values. Example 2-20
illustrates how the output statements work and also gives examples of expression s.
When an output statement outputs char values, it outputs the character without the
single quotation marks (unless the single quotation marks are part of the output state-
ment). For example, suppose ch is a char variable and ch = 'A'; . The statement:
System.out.println(ch);
or:
System.out.println('A');
outputs:
A
Similarly, when an output statement outputs the value of a string, it outputs the string
without the double quotation marks (unless you include double quotation marks as part
of the string, using an escape sequence).
EXAMPLE 2-20
Consider the following statements. The output is shown to the right of each statement.
Statement
Output
1
System.out.println(29 / 4);
7
2
System.out.println("Hello there.");
Hello there.
3
System.out.println(12);
12
4
System.out.println("4 + 7");
4 + 7
5
System.out.println(4 + 7);
11
6
System.out.println('A');
A
7
System.out.println("4 + 7 = " + (4 + 7));
4 + 7 = 11
8
System.out.println(2 + 3 * 5);
17
9
System.out.println("Hello \nthere.");
Hello
there.
Look at the output of statement 9. Recall that in Java, the newline character is '\n' ;it
causes the insertion point to move to the beginning of the next line before printing.
 
Search WWH ::




Custom Search