Java Reference
In-Depth Information
LISTING 2.4
//********************************************************************
// Roses.java Author: Lewis/Loftus
//
// Demonstrates the use of escape sequences.
//********************************************************************
public class Roses
{
//-----------------------------------------------------------------
// Prints a poem (of sorts) on multiple lines.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.println ("Roses are red,\n\tViolets are blue,\n" +
"Sugar is sweet,\n\tBut I have \"commitment issues\",\n\t" +
"So I'd rather just be friends\n\tAt this point in our " +
"relationship.");
}
}
OUTPUT
Roses are red,
Violets are blue,
Sugar is sweet,
But I have "commitment issues",
So I'd rather just be friends
At this point in our relationship.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 2.1
What is a string literal?
SR 2.2
What is the difference between the print and println methods?
SR 2.3
What is a parameter?
SR 2.4
What output is produced by the following code fragment?
System.out.println ("One ");
System.out.print ("Two ");
System.out.println ("Three ");
 
Search WWH ::




Custom Search