1. Member
Join Date
Aug 2010
Posts
2
Rep Power
0

## 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.

If we input 6 then the pattern will be like above. If input is 3,then the pattern will be like below

Can someone help me :confused:

I try this logic,but still not sucessfull :confused:
Java 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();
}```
Last edited by crazy4fun; 08-14-2010 at 05:24 PM.

2. 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
Last edited by JosAH; 08-15-2010 at 10:09 AM.

3. Member
Join Date
Aug 2010
Posts
2
Rep Power
0
I still can't figure out how to make space in center :confused:
Can you give more hint :confused:

4. 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:

Java 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:

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

kind regards,

Jos
Last edited by JosAH; 08-15-2010 at 10:07 AM.

5. Member
Join Date
Mar 2011
Location
West Bengal
Posts
29
Rep Power
0

*******
******
*****
****
Last edited by arunjib; 03-08-2011 at 09:02 AM.

6. 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

7. Member
Join Date
Mar 2011
Location
West Bengal
Posts
29
Rep Power
0

## 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

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

8. 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

#### Posting Permissions

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