Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

Presenting Credits 73

18: role1 + “\t” + actor1 + “\n” +
19: role2 + “\t” + actor2 + “\n” +
20: role3 + “\t” + actor3 + “\n” +
21: role4 + “\t” + actor4);
22: }
23: }


Look over the program and see whether you can figure out what it’s doing
at each stage. Here’s a breakdown of what’s taking place:


. Line 1 gives the Java program the name Credits.
. Line 2 begins the main()block statement in which all of the pro-
gram’s work gets done.
. Lines 4–14 set up variables to hold information about the film, its
director, and its stars. One of the variables, year, is an integer. The
rest are string variables.
. Lines 16–21 are one long System.out.println()statement.
Everything between the first parenthesis on Line 16 and the last
parenthesis on Line 21 is displayed onscreen. The newline character
(\n) causes the text after it to be displayed at the beginning of a new
line. The tab character (\t) inserts tab spacing in the output. The rest
are either text or string variables that should be shown.
. Line 22 ends the main()block statement.
. Line 23 ends the program.


If you do encounter error messages, correct any typos you find in your ver-
sion of the Creditsprogram and save it again. NetBeans compiles the pro-
gram automatically. When you run the program, you see an output win-
dow like the output pane in Figure 6.1.


LISTING 6.1 Continued


FIGURE 6.1
The output of the Credits
program.
Free download pdf