Results 1 to 14 of 14
  1. #1
    GeeKunMow is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default Star pattern help?

    I need some help making some star patterns. The exact instructions are as follows:

    Create separate programs to produce the following patterns:
    a.
    *
    **
    ***
    ****
    *****

    b.
    *****
    ****
    ***
    **
    *


    I have to use for loops to get the patterns and I've already got (a.) but I can't seem to get the second. My first pattern's code is this:

    public class Stars
    {
    //-------------------------------------------
    //Prints a triangle shape using asterick (star) characters.
    //-----------------------------------------------------------
    public static void main (String[] args)
    {
    final int MAX_ROWS = 10;

    for (int row = 1; row <= MAX_ROWS; row++)
    {
    for (int star = 1; star <= row; star++)
    System.out.print ("*");

    System.out.println();
    }
    }
    }
    Please help? Thanks in advance!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Simply do the process in other way around.

    Java Code:
    public class Stars {
    //-------------------------------------------
    //Prints a triangle shape using asterick (star) characters.
    //-----------------------------------------------------------
    
        public static void main (String[] args) {
    
            final int MAX_ROWS = 10;
            for (int row = MAX_ROWS; row >= 0; row--) {
                for (int star = 1; star <= row; star++) {
                    System.out.print ("*");
                }
                System.out.println();
            }
        }
    }

  3. #3
    GeeKunMow is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    Oh, wow. Thank you so much! I really appreciate it.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    jhen is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Smile star

    can i hav the explanation for the code u hv sent a while ago about creating a star?? coz i am little bit confuse?
    Last edited by jhen; 11-19-2008 at 03:37 AM.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  7. #7
    jhen is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default star

    wt is the used of final in the source code of creating a star??? y is it the identifier named row and star doesn't hav error eventhough it was not declared???
    plz i nid uir help... tnx

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    In Java final means constant. Basically the value cannot change at run time. Always it remain as the same. Just remove the word final and run the code. Still you get the same result. It's just for safety, in this case it's not much important but it's good practice.

    Carefully check the code, both start and row identifiers are declared in the code.

  9. #9
    jhen is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default TY

    tnx:).... it's a help for me to be one of the member of this forum....sayoonara....

  10. #10
    ultraman150 is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    thx. helped me out a bit in mine.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by ultraman150 View Post
    thx. helped me out a bit in mine.
    a bit :p So why don't you discuss you question with us and find the solution.

  12. #12
    praveenk1006 is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default java Code for Butterfly pattern....!

    can i get some help in generating a code of d pattern given below....!!!!


    *-----*
    -*---*
    *-*-*-*
    -*-*-*
    *-*-*-*
    -*---*
    *-----*
    hope i get a workin code for dis or at least d main logic... Thanks i Advance..... :) :)
    Last edited by praveenk1006; 07-13-2011 at 07:56 PM.

  13. #13
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    This thread is quite old, please make your own new post and show your work if you want the most help.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Strategy Pattern
    By mew in forum New To Java
    Replies: 0
    Last Post: 01-25-2008, 07:34 PM
  2. Singleton Pattern
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-24-2008, 03:21 PM
  3. singleton pattern
    By Peter in forum Advanced Java
    Replies: 1
    Last Post: 07-09-2007, 04:45 AM

Posting Permissions

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