Escape Sequences and Format Specifiers Example in java

Write a java Program that illustrates various escape sequences and format specifiers like backspace, hex representation, Carriage return, tab space and more.

Program or Solution


class Program


public static void main(String args[])


                // Escape Sequences

// \b back space deletes the previous character

System.out.printf("Hello\b World\n");


                // \n New line moves cursor to new line before printing World


                // \t tab space leaves a tab space before World

System.out.printf("Hello\t World\n"); 

// \r Carriage Return Moves cursor to starting position in the same line so Devil will be Over Written

System.out.printf("Hello World \rDevil\n"); 

// \" prints double Quotes

System.out.printf("\"Decode School\"\n");

// \\ Prints slash, so a\b 



                // Format Specifiers

// .2f   two digit precision in floating point numbers 


// %x hexa representation (a for 10)


// %o Octal representation (12 for 10)


// %b Boolean representation





Escape Sequences and Format Specifiers Example in java Output

Program Explanation

Escape Sequence begins with \

Format Specifier Begins with %