• Post Reply Bookmark Topic Watch Topic
  • New Topic

2D array program output problem  RSS feed

 
jay pattyy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that takes user input and turns it into big letters. I am stuck on the output part the program prints the letters vertically I need them to print horizontally any help will be appreciated.




 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are all letters equal in height and/or width? Are there letters that extend beneath the base line (like the small letter 'g')?

And of course: welcome to the ranch!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you mean your program is printing like:

A
B
C

(but with your big letters), but you want it to print

A B C

The problem is, once you print and move to the next line, you can't go back. So because you are printing the "top" of the A and then move to the next line, there's no way to go back to where you want to print the "top" of your B.

What you'll need to do is figure out everything you want to print, and print all the desired "top" lines of each letter, all concatenated together. Then move to the second line, and print each letter...etc. I'd probably write methods that build strings to represent each line, appending everything together.  So i'd have something like

String [] outputLines = new String [5];

So outputLines[0] would eventually equal "######  ######"
So outputLines[1] would eventually equal "#         #  #         #"
etc.

After you completely build all five, print them.




Now, this is not what you asked about, but this is terrible code;


Any time you repeat the same hunk of code over and over, you should think about a loop.  This could effectively be replaced with:



(note: that's not tested so may not be 100% correct. I'm just trying to show the idea).

You should be able to do something similar to address the "A" vs "B" vs "C" as the first index.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!