Solution for
Programming Exercise 2.1
THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook.
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 cut-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 cut-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 ]