# Thread: Asterisks and looping! surely you have a pritier solution than mine

1. Senior Member
Join Date
Apr 2012
Posts
115
Rep Power
0

## Asterisks and looping! surely you have a pritier solution than mine

My task from my book was to output these:

*
**
***
****
*****
******
*******
********
*********
**********

**********
*********
********
*******
******
*****
****
***
**
*

**********
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*********
**********

I did this, with the following code

Java Code:
```package chapter_v;

public class TrianglePrintingProgram_5_15
{
public static void main(String[] args)
{
String chain = "";

for(int i = 1 ; i <= 10 ; i++)
{
chain = chain + "*";
System.out.print(chain);
if(chain.length() == i)
{
System.out.println();
}

}

System.out.println();
chain = "**********";
for(int i = 10 ; i >= 1 ; i--)
{
System.out.print(chain);
System.out.println();
chain = chain.substring(0, chain.length() - 1);
}

System.out.println();
chain = "**********";
for(int i = 10 ; i >= 1 ; i--)
{
System.out.print(String.format("%10s", chain));
System.out.println();
chain = chain.substring(0, chain.length() - 1);
}

for(int i = 1 ; i <= 10 ; i++)
{
chain = chain + "*";
System.out.print(String.format("%10s", chain));
if(chain.length() == i)
{
System.out.println();
}

}
}
}```
I just dont like my solutions that much... I feel there are more elegant looping solutions that produce the same output. I was wondering how you professionals would do this (help me think like a programmer). common, I must of cheated with the formatting for the mirrored counterparts

2. Senior Member
Join Date
Apr 2012
Posts
115
Rep Power
0

## Re: Asterisks and looping! surely you have a pritier solution than mine

last two didnt represent the product after pasting should be mirrors

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•