• 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

Request hint

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could some of you please give me some hints, how to make the following pattern with the use of 'for'loop?
*
**
***
****
*****
Thanks in advance!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
People here will generally not do your homework for you.
Why not code up what you do know and post your code with questions regarding where you are getting hung up?
bear
 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand your apprehension, and that is the reason I have not asked for codes, just for hints.
First, I know how to generate this pattern without using 'for' loop, which is tedious and not the right way.
Second, I can create a nested 'for' loop and generate the following pattern:
****
****
****
But I do not know, how to increase the '*' in subsequent line.
I would appreciate any hint in this regard.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the concatentation operator
bob is of type STRING.
bob = bob + "*";
OR its shorthanded equivalent
bob += "*";
OR a funkier way to do it is by way of:
System.out.print("*")
this will print a string and won't wrap to the next line.
I'd recommend figuring out how to do it using the first way.
[ July 14, 2003: Message edited by: Eric Hoskland ]
 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Friend! I have got it.
I have used String X ="X"; and X =X +"X"; It has worked.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With a little bit more thought, I'd bet you could figure it out, without using String concatenation (not that there's anything really wrong with such a solution). Think "nested for loops", as you once did.
 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dirk,for your thought!
I did generate the pattern with nested "for" loop:
for (int i=5; i>=0; i--){
for(int j=i;j>=0; j--){
System.out.print("X");
}
System.out.println();
}
 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, It should be increment operator not decrement.
Thanks!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done, Jit.
Note that you have the ability to edit your own posts. Just click on the icon abover the post that looks like a piece of paper.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic