SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Stuart Reges, Marty Stepp
Chapter:
Introduction To Java Programming
Exercise:
Programming Projects
Question:1 | ISBN:9780136091813 | Edition: 2

Question

Write a program to spell out MISSISSIPPI using block letters like the following (one per line):

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

public class Ch01PP01
{
	public static void main(String[] args)
	{
		printM();
		printI();
		printS();
		printS();
		printI();
		printS();
		printS();
		printI();
		printP();
		printP();
		printI();
	}
	
	public static void printM()
	{
		System.out.println("M     M");
		System.out.println("MM   MM");
		System.out.println("M M M M");
		System.out.println("M  M  M");
		System.out.println("M     M");
		System.out.println("M     M");
		System.out.println("M     M");
		System.out.println();
	}
	
	public static void printI()
	{
		System.out.println("IIIII");
		System.out.println("  I");
		System.out.println("  I");
		System.out.println("  I");
		System.out.println("  I");
		System.out.println("  I");
		System.out.println("IIIII");
		System.out.println();
	}
	
	public static void printS()
	{
		System.out.println(" SSSSS");
		System.out.println("S     S");
		System.out.println("S");
		System.out.println(" SSSSS");
		System.out.println("      S");
		System.out.println("S     S");
		System.out.println(" SSSSS");
		System.out.println();
	}
	
	public static void printP()
	{
		System.out.println("PPPPPP");
		System.out.println("P     P");
		System.out.println("P     P");
		System.out.println("PPPPPP");
		System.out.println("P");
		System.out.println("P");
		System.out.println("P");
		System.out.println();
	}
}

Output:

M     M
MM   MM
M M M M
M  M  M
M     M
M     M
M     M

IIIII
  I
  I
  I
  I
  I
IIIII

 SSSSS
S     S
S
 SSSSS
      S
S     S
 SSSSS

 SSSSS
S     S
S
 SSSSS
      S
S     S
 SSSSS

IIIII
  I
  I
  I
  I
  I
IIIII

 SSSSS
S     S
S
 SSSSS
      S
S     S
 SSSSS

 SSSSS
S     S
S
 SSSSS
      S
S     S
 SSSSS

IIIII
  I
  I
  I
  I
  I
IIIII

PPPPPP
P     P
P     P
PPPPPP
P
P
P

PPPPPP
P     P
P     P
PPPPPP
P
P
P

IIIII
  I
  I
  I
  I
  I
IIIII

 

0 0

Discussions

Post the discussion to improve the above solution.