• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help me write this method!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea how to even approach this.. beginner here, any help would be appreciated I can't seem to figure out how to get even spacing to form a pyramid

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 starPrinter(int n) .

e.g.



Thank you so much!
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its simple..

You have to start from 1,

keep on adding 2 in every loop run until you reach n..

for number of spaces you have to leave (int)(n/2) spaces before and after your print.. and you have to decrease this number every new line by 2..
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"king java", please check your private messages regarding an important administrative matter.
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please ShowSomeEffort by showing us what you have done up to now?
You may also find some interesting instructions in HowToAskQuestionsOnJavaRanch
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using for loops, first without the spaces like this:

*
***
*****

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vicky chauhan wrote: . . . spaces before and after your print . . .

No, you only need spaces before printing; nobody will ever know whether you have spaces after the ***
 
reply
    Bookmark Topic Watch Topic
  • New Topic