sai rama krishna wrote:please advise
After looking at your code, I see that you must have just got mixed up with "trailing" and "leading" -- there is a difference you know. The
word "trailing" means
after while "leading" means
before. Be careful with the terms you use so you don't cause misunderstandings.
I think your mind is trapped and entangled by all the details you're trying to work out. Ignore the details first. Describe at a high level what you're trying to do. If you can't even do that much, to get a big picture idea of what EXACTLY you want to do, then how do you expect to put all the minute detailed parts together to make it actually work?
Break down the large problem into smaller chunks. Then break each small chunk into even smaller chunks. Keep doing that until you get to a point where you
have to write detailed code. At that point, the details will be so small and focused that it will be trivial to write.
I'll start you off:
HIGH LEVEL: Print a triangle from numbers entered by the user
NEXT LEVEL:
Given a
String entered by the user,
Split the String up into an array that has 1 element per character in the String
Print each character as a line in the pyramid.
NEXT LEVEL: (print each character as a line in a the pyramid)
Print leading spaces
Print the character
Print a linefeed
NEXT LEVEL: (continue this breakdown)
You need to learn how to organize your thoughts, break down tasks, and attack the problem systematically and logically.
What you have been doing so far seems to little more than just pure guessing. You can't write correct programs by guessing. Think, plan, organize. That's how you can get it done. If you learn how to use the above approach, you can solve this problem in less than 15 minutes.