English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need help on Java program i have to make. It states:

Write a program which receives three input characters and outputs your printed initials in large size (at least 2 inches high) using the 3 input characters stored in string variables.

so it ends up something like this:

L
L
L
L
LLLLLLLL

2007-08-22 10:24:30 · 2 answers · asked by amitpop22 2 in Computers & Internet Programming & Design

dude, this is extra credit. We did not learn it in class. my teacher said we could use help if needed.

2007-08-22 10:40:46 · update #1

2 answers

Most of the work is going to be defining the "font", assuming every output character will be an array of 5 strings (one String for each line of output). That requires you to assemble 26 5-string arrays, one for each initial.

You'll have something like this, an array of arrays, where each lower-level array is the five Strings that correspond to the five lines of each character:

String[][] font = new String[][] {
{ "___A___", "__A_A__", "_A___A_", "AAAAAAA", "A_____A" },
{ "BBBBBB_", "B_____B", "BBBBBB_", "B_____B", "BBBBBB_" },
// and so on for C to Z
// Note that I used '_' instead of space,
// because Yahoo collapses spaces.
};

Then the loop to output the three initials will be to print the first line of each, then go to a new line, then print the second line of each, and so on:

============================
// Just for testing. You can handle the
// input and uppercasing, I assume
String initials = "ABA";

// This is the useful part

// For each line
for (int lineNo=0; lineNo<5; ++lineNo) {
// For each initial on the line
for (int charIdx=0; charIdx< initials.length(); ++charIdx) {
int charNo = ((int) initials.charAt( charIdx )) - 'A';
System.out.print( font[charNo ][ lineNo] );
// Space between adjacent initials
System.out.print(" ");
}
// Move on to the next line of output
System.out.println();
}
============================
Sample output of that test program (it only looks good in fixed-pitch font, though):

___A___ BBBBBB_ ___A___
__A_A__ B_____B __A_A__
_A___A_ BBBBBB_ _A___A_
AAAAAAA B_____B AAAAAAA
A_____A BBBBBB_ A_____A

2007-08-22 11:55:03 · answer #1 · answered by McFate 7 · 0 0

You really want us to do your homework for you? Maybe you should try studying, or paying attention in class.

2007-08-22 10:32:55 · answer #2 · answered by J P 4 · 0 0

fedest.com, questions and answers