Hi,
I need to build the triangle like below.Please give hint to solve this using loops.
* * * * * * * * * * * * * * *
thanks in advance.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi,
I need to build the triangle like below.Please give hint to solve this using loops.
* * * * * * * * * * * * * * *
thanks in advance.
Last edited by Ganeprog; January 16th, 2014 at 09:36 AM. Reason: triangle shape changed
Hi, read this Announcements - What's Wrong With My Code? to find out how to post formatted code and to preserve formatting.
Then show what you've tried. Ask specific questions, post sample runs, errors, etc. Then we can give hints.
I tried but i dont know how to start this. give some hint or idea to solve this above triangle or Please provide some initiation point to start
First, I imagine you want (or you have been asked to do) to have a variable that contains the "height" of the triangle, e.g.:
int height = 5;
And given only this value, generate dynamically the triangle, so that changing this value you get another correct triangle.
You need a main loop (for) cycle for each row, I think this is quite trivial. For each row you need to do another loop, some prints but also few calculations.
If you want to have a fixed number of spaces at the beginning of each line, it's ok, it's a simple fixed println. Then you need a number of spaces that depends on the current row. On the first row, how many spaces do you need before the single "*" in order to have this centered?
And you need a space between two consecutive "*".
So please, start from these considerations.
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code
public class MyTriangle{ public static void main(String args[]){ MyTrinagle mt = new MyTriangle(); // up to you .... } }