Page 97 - Introduction to Programming with Java: A Problem Solving Approach
P. 97
Figure 3.2 Sayings program and its associated output
method call is longer than the second println method call and as such, it could not fit on two lines if it
was split after the left parenthesis. In other words, this does not work:
System.out.println(
"If you are not part of the solution, you are part of the pr
⎯⎯
Thus, we split the third println method call in the middle of the string that is to be printed. To split a string literal, you need to put opening and closing quotes around each of the two split-apart substrings, and you need to insert a + between the substrings. See the quotes and the + in Figure 3.2’s third println method call.
3.8 Compilation and Execution
Up to this point in the chapter, you’ve been exposed only to the theory behind Java code (the theory behind the Dream program’s code and the theory behind the Sayings program’s code). To gain a more complete appreciation for code, you need to enter it on a computer, compile it, and run it. After all, learning how to program requires lots of hands-on practice. It’s a “contact sport”! We’ve provided several tutorials on the
3.8 Compilation and Execution 63
/********************************************************************
*
Sayings.java
Dean & Dean
This program prints several sayings.
*********************************************************************/
*
*
*
public class Sayings
{
public static void main(String[] args)
{
System.out.println("The future ain't what it used to be.");
System.out.println(
"Always remember you're unique, just like everyone else.");
System.out.println("If you are not part of the solution," +
" you are part of the precipitate.");
}
// end class Sayings
} // end main
Output:
The future ain't what it used to be.
Always remember yoAu'preaugnioque,PjDusFt liEkenehvearynonceelrse.
If you are not part of the solution, you are part of the precipitate.
This connects/concatenates the split-apart strings.
N
N
o
o
t
t
e
en
n
o
ou
u
g
gh
h
r
r
o
o
o
om
m.
.