programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Writing a large symbol in the console

Patrick Perrin Smith
Greenhorn
Posts: 7
This might sound like a slightly odd question, so bear with me.

What I'm tasked to do, is to make a simple Java class that forms a "V" based on whatever height the user would desire, made out of stars "*", and spaces " ".

For example, if a user desires a "V" with a height of 3, it would look print out something like;

Where a "V" with a height of 5 would look something like:

(That one didn't look too good, but you get the point, it's suppose to be 5 "high" and shaped like a "V")

The problem I have, is that I don't see what loops within loops within loops I would need to build something like this.

All the easy stuff like asking the user what height they want and such, I can handle, but I don't see how this thing is suppose to be coded, to print out a decent-looking and right-sized "V" in the console.

Can anyone assist me in this odd matter?

In order to not come off as lazy, I tried poking around a little to see what I could come up with to give you guys a clearer example of what I need.

Looked like something of a good start, and it drew me half (!) of the "V" in the size I wanted.

Am I on to it here, or am I on the moon in terms of progress?

I need the entire "V", not just a nice "\".

In layman terms; what do?

Paweł Baczyński
Bartender
Posts: 2083
44
• 1

Suppose a height is h
To print a line you need to know:
- How many spaces to put before first *
- How many spaces to put between first and second *
given line number n (I am assuming a line number is 1..n)

How do you calculate it? (not in Java, but on paper)

If you know how to print a single line given h and n, then looping from 1 to h will be trivial.
NOTE: don't even look at this code until you figure out how to solve this on paper!

Jayesh A Lalwani
Rancher
Posts: 2762
32
Patrick Perrin Smith wrote:
(That one didn't look too good, but you get the point, it's suppose to be 5 "high" and shaped like a "V")

Actually, this might be the problem. You need to figure out how to make the V look good on paper before you code. As Pawel says StopCoding

For every given line, you know you will have a bunch of spaces, a star, then a bunch of spaces, then another star. Take a graph paper (or absent a graph paper, just draw a grid on plain paper), and draw a spiffy looking V on it by hand. Count the spaces on each line, and see if you find a pattern. Then draw a bigger V, and then do the same and see if your pattern applies. Once you get the pattern, you have your algorithm

Patrick Perrin Smith
Greenhorn
Posts: 7
Not a bad idea guys! I think I'll get some paper-work going before attempting the code again. Thanks!