Results 1 to 8 of 8
  1. #1
    crazy4fun is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

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

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    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 09:09 AM.

  3. #3
    crazy4fun is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default

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

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by crazy4fun View Post
    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);
    }
    Your turn now ...

    kind regards,

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

  5. #5
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

    Default

    i want to print the following pattern, please help me

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

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by arunjib View Post
    i want to print the following pattern, please help me

    *******
    ******
    *****
    ****
    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
    The only person who got everything done by Friday was Robinson Crusoe.

  7. #7
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

    Default 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 View Post
    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. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by arunjib View Post
    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
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Star pattern help?
    By GeeKunMow in forum New To Java
    Replies: 13
    Last Post: 07-21-2011, 05:59 AM
  2. Class pattern to generate following pattern:-
    By vxs in forum New To Java
    Replies: 5
    Last Post: 07-14-2010, 11:15 PM
  3. intricate star pattern
    By aamster in forum New To Java
    Replies: 7
    Last Post: 10-11-2009, 06:50 AM
  4. Recursive Star Pattern HELP PLEASE!!
    By ITnewbie in forum New To Java
    Replies: 1
    Last Post: 09-25-2009, 09:55 PM

Posting Permissions

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