Introduction To Java Programming
Introduction To Java Programming
– 2. System.out.println();
• Prints a blank line on the console.
"This is a string"
CS305j Introduction to Introduction to Java Programming 22
Computing
Details about Strings
A string literal may not span across multiple lines.
"This is not
a legal String."
A "quoted" String is
'much' better if you learn
the rules of "escape sequences."
System.out.println("\ta\tb\tc");
System.out.println("\\\\");
System.out.println("'");
System.out.println("\"\"\"");
System.out.println("C:\nin\the downward spiral");
a b c
\\
'
"""
C:
in he downward spiral
}
Example:
public static void printCheer() {
System.out.println(“Three cheers for Pirates!");
System.out.println(“Huzzah!");
System.out.println(“Huzzah!");
System.out.println(“Huzzah!");
}
Program's output:
A partridge in a pear tree.
Two turtle doves, and
A partridge in a pear tree.
CS305j Introduction to Introduction to Java Programming 37
Computing
Control flow of methods
When a method is called, a Java program 'jumps'
into that method, executes all of its statements, and
then 'jumps' back to where it started.
public class TwelveDays {
public static void main(String[] args) {
day1();
}
public static void day2() {
System.out.println("Two turtle doves, and");
day1();
} }
Write a program that prints the following output to the console. Use
static methods as appropriate.
Lollipop, lollipop
Oh, lolli lolli lolli
Lollipop, lollipop
Oh, lolli lolli lolli
Call my baby lollipop
You may not use char or while or this or any other keyword for the name of
a class or method; Java reserves those words to mean other things.
– You could use CHAR, While, or ThIs, because Java is case-sensitive. However, this
could be confusing and is not recommended.
displayVerse();
}