Java Reference
In-Depth Information
LISTING 2.1
Continued
5: byte initialLevel = 12;
6: short location = 13250;
7: int score = 3500100;
8: boolean newGame = true;
9:
10: System.out.println(“Level: “ + initialLevel);
11: System.out.println(“Up: “ + UP);
12: }
13: }
2
Compile this application and run the class file Variables.class . This program produces
the following output:
Level: 12
Up: U
This class uses four local variables and one constant, making use of System.out.
println() in lines 10-11 to produce output.
System.out.println() is a method called to display strings and other information to the
standard output device, which usually is the screen.
System.out.println() takes a single argument within its parentheses: a string. To pre-
sent more than one variable or literal as the argument to println() , you can use the “+”
operator to combine these elements into a single string, which will be described later
today.
There's also a System.out.print() method, which displays a string without terminating
it with a newline character. You can call print() instead of println() to display several
strings on the same line.
Comments
One of the most important ways to improve the readability of your program is to use
comments. Comments are information included in a program strictly for the benefit of
humans trying to figure out what's going on in the program. The Java compiler ignores
comments entirely when preparing a runnable version of a Java source file.
There are three different kinds of comments you can use in Java programs, and you can
use each of them at your discretion.
 
 
Search WWH ::




Custom Search