Results 1 to 8 of 8
Thread: Star triangle pattern
- 08-14-2010, 04:21 PM #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 04:24 PM.
- 08-14-2010, 04:41 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosLast edited by JosAH; 08-15-2010 at 09:09 AM.
- 08-14-2010, 04:57 PM #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:
- 08-14-2010, 05:05 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
The following code snippet prints n stars followed by a space, followed by n stars again:
As you might have noticed that little method uses another little method: printRow, here it is:Java Code:private static void printLayer(int n) { printRow('*', n); System.out.print(' '); printRow('*', n); }
Your turn now ...Java Code:private static void printRow(char c, int n) { for (int i= 1; i <= n; i++) System.out.print(c); }
kind regards,
JosLast edited by JosAH; 08-15-2010 at 09:07 AM.
- 03-06-2011, 10:41 AM #5
Member
- Join Date
- Mar 2011
- Location
- West Bengal
- Posts
- 29
- Rep Power
- 0
i want to print the following pattern, please help me
*******
******
*****
****Last edited by arunjib; 03-08-2011 at 08:02 AM.
- 03-06-2011, 12:22 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 03-06-2011, 01:01 PM #7
Member
- Join Date
- Mar 2011
- Location
- West Bengal
- Posts
- 29
- Rep Power
- 0
- 03-06-2011, 01:03 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Star pattern help?
By GeeKunMow in forum New To JavaReplies: 13Last Post: 07-21-2011, 05:59 AM -
Class pattern to generate following pattern:-
By vxs in forum New To JavaReplies: 5Last Post: 07-14-2010, 11:15 PM -
intricate star pattern
By aamster in forum New To JavaReplies: 7Last Post: 10-11-2009, 06:50 AM -
Recursive Star Pattern HELP PLEASE!!
By ITnewbie in forum New To JavaReplies: 1Last Post: 09-25-2009, 09:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks