Download public class EscapeQuiz

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Hello World
AP Computer Science
Below is a simple program which outputs Hello World! Open a new BlueJ project called FirstProject
and copy the following into a class called HelloWorld. Compile and run it to make sure it works.
/**
* This program writes: Hello World!
*
* @author (Haas)
* @version (V1 Fall 2015)
*/
public class HelloWorld // class names should begin with a capital
{
/*
* all programs must
* have a main method
*/
public static void main(String[] args)
{
System.out.println("Hello World"); // prints to the screen
}
}
Note: in Java there are 3 ways to make comments:
// single line
/*
multiple
line
*/
/**
multiple line for
javadoc (special documentation)
*/
Modify the lines of code within the main method as follows and determine what happens.
System.out.println("Hello");
System.out.println("world");
System.out.print("Hello");
System.out.print("world");
Escape characters (also called escape sequences or escape codes)
What if you wanted to print: Mr. Haas said “Hello” How would you do it?
In Java, a character preceded by a backslash (\) is an escape sequence and has special meaning to the
java compiler. Try to figure the function of the following escape sequences:
System.out.println("I like \npizza.");
System.out.println("I like \tpizza.");
System.out.println("I like \"pizza.");
System.out.println("I like \\pizza.");
Escape Sequence
What is its function?
\n
_________________________________
\t
_________________________________
\"
_________________________________
\\
_________________________________