[ Exercises | Chapter Index | Main Index ]

Solution for Programmming Exercise 2.1


This page contains a sample solution to one of the exercises from Introduction to Programming Using Java.


Exercise 2.1:

Write a program that will print your initials to standard output in letters that are nine lines tall. Each big letter should be made up of a bunch of *'s. For example, if your initials were "DJE", then the output would look something like:

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

Discussion

This is a very simple program. It consists of nothing but a sequence of System.out.println statements. (Alternatively, you could use TextIO.putln.) The hard part is designing the letters. You have to experiment in your text editor until you get letters that look right to you. Add System.out.println(" at the beginning of the first line, then copy-and-paste it to the beginning of each of the other lines. (You don't need to type it out on each line! Creative use of copy-and-paste can save you a lot of work.) Then add "); to the end of each line. In my program, I've also added a System.out.println() statement at the beginning and the end. The extra blank lines make the output look better.

Don't forget that in order to have a complete program, you have to put the program statements in a main subroutine and put that subroutine in a public class.


The Solution

    public class PrintInitials {
      
       /*  This program prints my initials (DJE) in big letters,
           where each letter is nine lines tall.
       */
    
       public static void main(String[] args) {
          System.out.println();
          System.out.println("           ******           *************        **********");
          System.out.println("           **    **                **            **");
          System.out.println("           **     **               **            **");
          System.out.println("           **      **              **            **");
          System.out.println("           **      **              **            ********");
          System.out.println("           **      **       **     **            **");
          System.out.println("           **     **         **    **            **");
          System.out.println("           **    **           **  **             **");
          System.out.println("           *****               ****              **********");
          System.out.println();
       }  // end main()

    }  // end class

[ Exercises | Chapter Index | Main Index ]