Java program to format text