• Post Reply Bookmark Topic Watch Topic
  • New Topic

printing triangles - java exercise , help please!  RSS feed

 
Greenhorn
Posts: 23
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

here is java code that prints :


so the java code above will print this:


now i need to print same figures on the same level!


so i know how to print those figures below each other, but how do i print them all on the same level?

help me please!
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Restating the obvious, your program currently prints ASCII shapes sequentially:

A

B

C

D

and you need to change your design so that the 4 shapes are printed side-by-side:

A B C D

Since you're dealing with a console application and cursor placement in the console is restricted to increasing the cursor location to a column on the same row or to a greater row, you'll have to restructure your program to print a line of each shape on a single row of the console with each pass through your drawing loop. You might change your existing shape printing code into methods that print the specified line of the shape beginning at a certain column:



Some at your level are overwhelmed by the thought of using methods, or their use may be forbidden, but without methods, your main() method will have to contain the code to print each shape a line at a time. In essence, you'll be reduced to multiple println statements that look like:



Which, unless also forbidden, is A solution, inelegant, but a solution just the same.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!