Results 1 to 6 of 6
Thread: Help with this method please!
- 05-06-2010, 07:35 AM #1
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
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!
- 05-06-2010, 07:37 AM #2
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
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
- 05-06-2010, 07:56 AM #3
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
It should look like this:
- 05-06-2010, 08:42 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
What about using simple code tags instead?
btw why did you post this in the 'advanced' section?Java Code:* *** ***** ******* *********
kind regards,
Jos
- 05-09-2010, 03:52 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
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 (""); } }
-
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
ArrayLists compareTo method, equals method
By random0munky in forum New To JavaReplies: 2Last Post: 10-26-2009, 07:20 PM -
calling method from main method
By bob_bee in forum New To JavaReplies: 4Last Post: 10-02-2009, 05:30 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks