Escape sequences

A character preceded by a backslash () is an escape sequence and has special meaning to the compiler. The following table shows the Java escape sequences. Note: Each escape sequence represents one character entity.

Escape Sequence Description
\t Insert a tab in the text at this point.
\b Insert a backspace in the text at this point.
\n Insert a newline in the text at this point.
\r Insert a carriage return in the text at this point.
\f Insert a formfeed in the text at this point.
\' Insert a single quote character in the text at this point.
\" Insert a double quote character in the text at this point.
\ Insert a backslash character in the text at this point.

Write a Java program to print a box, an oval, and a diamond using asterisks.

********
*      *
*      *
*      *
*      *
********

  ***  
 *   *
*     *
*     *
 *   *
  ***

   *
  * *
 *   *
  * *
   *

Write a Java program to print a picture of my cat:

  |\_/|       
 / @ @ \      
( > º < )     
 `>>x<<´     
 /  O  \

What does the following print?

System.out.print("*");
System.out.println("***");
System.out.print("****");
System.out.println("*");

What does the following line of code print?

System.out.printf("%s\n%s\n%s\n","@","@@","@@@");

Write a Java program to print the following columns of values. Use \t for the tabs between the columns.

Cost      Quantity   Total
$1,000.00   4       $4,000.00
$   50.00   8         $400.00
______________________________
TOTAL:      12      $4,400.00

Write a Java program to print the escape sequences to the console.

\t    Insert a tab in the text at this point.
\b    Insert a backspace in the text at this point.
\n    Insert a newline in the text at this point.
\r    Insert a carriage return in the text at this point.
\f    Insert a formfeed in the text at this point.
\'    Insert a single quote character in the text at this point.
\"    Insert a double quote character in the text at this point.
\\    Insert a backslash character in the text at this point.