1. Member
Join Date
Aug 2009
Posts
1
Rep Power
0

## java problem

i need help for this problem...

"write a program that ask the user to enter the size of a triangle (1 to 50).then print the triangle by printing a series of lines consisting of asterisks.the first line will have 1 asterisk, the next two will have two and so on....with each line having one more asterisk than the previous line up to the number entered by the user.on the next line print one less asterisk and continue by decreasing the number of esterisk by 1 for each successive line until any one asterisk is printed."
hint: use nested loops, the outside loop controls the number of lines and the inside loops controls the number of asterisk to print on a line.

i hope, anyone will help me on this problem...pls....

2. What you've done is to post your entire assignment without showing what work you've done, and that is not how to get help here (or at any forum). For one, we have no idea what you're having trouble with, so we won't know how to advise you. For another, it suggests that you want someone to post a complete solution, thereby doing your homework for you, and I know that this was not your intent.

So please try to solve the problem first, and then post what you've done using code tags (see my signature), and then ask a specific question. Do this and you'll have many folks willing to help you.

Much luck!

3. ## Here it is

int input; //input from user

//Nested Loops
int count=0;

for(int i=0;i<input;i++)
{
for(int j=0;j<i;j++)
{
System.out.print("*");
}
System.out.println();
count=i;
}

if(count>=input-1)

{

for(int k=count;k>=0;k--)
{
for(int j=0;j<=k;j++)
{
System.out.print("*");
}
System.out.println();
}

}
================================================== ========
If the input =10;the result will be ass following:

*
**
***
****
*****
******
*******
********
*********
********** // 10(*)'s
*********
********
*******
******
*****
****
***
**
*

Java Forums - BB Code List

5. Senior Member
Join Date
Sep 2008
Posts
564
Rep Power
9
this is where you state what you actually need help with in your code...

6. Just giving away a code is not make sense lol. Better to give some guide first of all, otherwise our thread starter wont tryout anything new. That's not the way to learn.

Originally Posted by HosHos
int input; //input from user

//Nested Loops
int count=0;

for(int i=0;i<input;i++)
{
for(int j=0;j<i;j++)
{
System.out.print("*");
}
System.out.println();
count=i;
}

if(count>=input-1)

{

for(int k=count;k>=0;k--)
{
for(int j=0;j<=k;j++)
{
System.out.print("*");
}
System.out.println();
}

}
================================================== ========
If the input =10;the result will be ass following:

*
**
***
****
*****
******
*******
********
*********
********** // 10(*)'s
*********
********
*******
******
*****
****
***
**
*