Results 1 to 6 of 6
  1. #1
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Help with this method please!

    Write a public static method named starPrinter that will take an int as a parameter and print lines of stars as shown below.

    The header of the method will be public static void printStars(int n) .

    e.g.
    If the value of n is 5, then the method should print
    *
    ***
    *****
    *******
    *********

    If the value of n is 3, then the method should print
    *
    ***
    *****

    Please help!

  2. #2
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    it actually has to be shaped like a pyramid, the text format of this forum won't let me post the stars that way but it should look like a pyramid, not flat on one side like that

  3. #3
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    It should look like this:


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

    Default

    What about using simple code tags instead?
    Java Code:
        *
       ***
      *****
     *******
    *********
    btw why did you post this in the 'advanced' section?

    kind regards,

    Jos

  5. #5
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    I feel like this is a bad idea giving this away so easily, but what the hay.

    read this and try to understand it, post if you have questions:

    Java Code:
        public static void printPyramid (int n)
        {
            for (int i = 0 ; i < n ; i++)
            {
                for (int j = 0 ; j < n - 1 - i ; j++)
                {
                    System.out.print (" ");
                }
                for (int j = 0 ; j < i * 2 + 1 ; j++)
                {
                    System.out.print ("*");
                }
                System.out.println ("");
    
            }
        }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JosAH View Post
    btw why did you post this in the 'advanced' section?
    Jos
    Indeed. Moved.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. ArrayLists compareTo method, equals method
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 07:20 PM
  3. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 05:30 PM
  4. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 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
  •