# Star triangle pattern

• 08-14-2010, 05:21 PM
crazy4fun
Star triangle pattern
Hi there,I am very confused how to make star triangle pattern like pyramid when there is space in center. Input is using Scanner.
http://a.imageshack.us/img541/3944/capture1c.jpg

If we input 6 then the pattern will be like above. If input is 3,then the pattern will be like below
http://a.imageshack.us/img227/8952/capture2za.jpg
Can someone help me :confused:

I try this logic,but still not sucessfull :confused:
Code:

```                int MAX_ROWS = 5;                 int TREE_MID = 5;                 for (int row = 1; row <= MAX_ROWS; row++) {                         for (int star = 1; star <= TREE_MID+row; star++){                         if (star <= TREE_MID-row){                             System.out.print(" ");                             } else {                             System.out.print("*");                             }                         }                 System.out.println();                 }```
• 08-14-2010, 05:41 PM
JosAH
On line one there will be one star, a space and one star again; on line two there will be two stars, a space and two stars again; on line three there will be three stars, a space and three stars again; can you see a pattern here?

kind regards,

Jos
• 08-14-2010, 05:57 PM
crazy4fun
I still can't figure out how to make space in center :confused:
Can you give more hint :confused:
• 08-14-2010, 06:05 PM
JosAH
Quote:

Originally Posted by crazy4fun
I still can't figure out how to make space in center :confused:
Can you give more hint :confused:

The following code snippet prints n stars followed by a space, followed by n stars again:

Code:

```private static void printLayer(int n) {   printRow('*', n);   System.out.print(' ');   printRow('*', n); }```
As you might have noticed that little method uses another little method: printRow, here it is:

Code:

```private static void printRow(char c, int n) {   for (int i= 1; i <= n; i++)       System.out.print(c); }```

kind regards,

Jos
• 03-06-2011, 11:41 AM
arunjib

*******
******
*****
****
• 03-06-2011, 01:22 PM
JosAH
Quote:

Originally Posted by arunjib

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

You're hijacking someone else's thread again. Start your own thread; if you don't know how to do that, read the forum FAQs and/or manuals.

kind regards,

Jos
• 03-06-2011, 02:01 PM
arunjib
xyz
I am really sorry again! I really cannot start new thread. how can i get that problem solved if i dont put the question in any thread. can u please help me...?? i can provide my cell number too if it needed. but i need help for that problem

Quote:

Originally Posted by JosAH
You're hijacking someone else's thread again. Start your own thread; if you don't know how to do that, read the forum FAQs and/or manuals.

kind regards,

Jos

• 03-06-2011, 02:03 PM
JosAH
Quote:

Originally Posted by arunjib
I am really sorry again! I really cannot start new thread. how can i get that problem solved if i dont put the question in any thread. can u please help me...?? i can provide my cell number too if it needed. but i need help for that problem

Go to the 'New To Java' forum section; you see a listing of all posted threads; on top of that listing you see a button labeled 'New Thread'; press it and post your own new thread.

kind regards,

Jos