Advertisement
476179

PrintAndPrintlnMethods

Sep 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package lessons;
  2.  
  3. public class ThePrintAndPrintlnMethods
  4. {
  5.  
  6.     public static void main(String[] args)
  7.     {
  8. /* example 1, called a single in line comment
  9. *       'system' is a class that helps perform system
  10. *       level functions, 'out' is an object, 'println' is a method,
  11. *       method is in an object which is in a system
  12. */
  13.        
  14.         //ed 1 'println' method advances cursor to next line
  15.         System.out.println("Programming is fun");
  16.         System.out.println("King Arthur");
  17.        
  18.        
  19.         //ex 2 'print' method does not advance cursor to next line
  20.         System.out.print("programming is ");
  21.         System.out.println("great fun!");
  22.        
  23.         //ex 3
  24.         System.out.println();
  25.         System.out.println("these are out top sellers");
  26.         System.out.println();
  27.         System.out.println("computer games");
  28.         System.out.println();
  29.         System.out.println("coffee");
  30.         System.out.println();
  31.         System.out.println("asprin");
  32.         System.out.println();
  33.        
  34.         //ex 4 '\n' makes jvm advance cursor to next line, its called an escape sequence character
  35.         System.out.println("these are out top sellers");
  36.         System.out.println("computer games\nCoffee");
  37.         System.out.println("asprin");
  38.        
  39.         //ex 5
  40.         System.out.print("\nthis is my list:\nMilk\nEggs\nCookies");
  41.        
  42.         //ex 6 you can stack escape sequences, below is an ex of '\n\n'
  43.         // '\t' is another escape sequence character and it tabs in
  44.         System.out.print("\n\ntop sellers:\n");
  45.         System.out.print("\tcomputer games\n\tCoffee\n");
  46.         System.out.println("\tasprin");
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement