Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- public class ThePrintAndPrintlnMethods
- {
- public static void main(String[] args)
- {
- /* example 1, called a single in line comment
- * 'system' is a class that helps perform system
- * level functions, 'out' is an object, 'println' is a method,
- * method is in an object which is in a system
- */
- //ed 1 'println' method advances cursor to next line
- System.out.println("Programming is fun");
- System.out.println("King Arthur");
- //ex 2 'print' method does not advance cursor to next line
- System.out.print("programming is ");
- System.out.println("great fun!");
- //ex 3
- System.out.println();
- System.out.println("these are out top sellers");
- System.out.println();
- System.out.println("computer games");
- System.out.println();
- System.out.println("coffee");
- System.out.println();
- System.out.println("asprin");
- System.out.println();
- //ex 4 '\n' makes jvm advance cursor to next line, its called an escape sequence character
- System.out.println("these are out top sellers");
- System.out.println("computer games\nCoffee");
- System.out.println("asprin");
- //ex 5
- System.out.print("\nthis is my list:\nMilk\nEggs\nCookies");
- //ex 6 you can stack escape sequences, below is an ex of '\n\n'
- // '\t' is another escape sequence character and it tabs in
- System.out.print("\n\ntop sellers:\n");
- System.out.print("\tcomputer games\n\tCoffee\n");
- System.out.println("\tasprin");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement