Java Reference
In-Depth Information
There is a second method, called print , that you can use to print an item without
starting a new line. For example, the output of the two statements
System.out.print("00");
System.out.println(3 + 4);
is the single line
007
S YNTAX 1.1 Method Call
object.methodName (parameters)
Example:
System.out.println("Hello, Dave!")
Purpose:
To invoke a method on an object and supply any additional parameters
21
22
S ELF C HECK
12. How would you modify the HelloPrinter program to print the words
ȒHello,ȓ and ȒWorld!ȓ on two lines?
13. Would the program continue to work if you omitted the line starting with
// ?
14. What does the following set of statements print?
System.out.print("My lucky number is");
System.out.println(3 + 4 + 5);
C OMMON E RROR 1.1: Omitting Semicolons
In Java every statement must end in a semicolon. Forgetting to type a semicolon is a
common error. It confuses the compiler, because the compiler uses the semicolon to
find where one statement ends and the next one starts. The compiler does not use
Search WWH ::




Custom Search