• 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

Nested Loops Pattern

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to develop and run a program that generates the following output

1
234
56789
234
1

I can't figure out how to make it anything other than
1
12
123
1234
12345
123456
1234567
12345678
123456789

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

That looks like a recursive problem to me, but you probably don’t know about recursion yet.
Get a sheet of paper, a pencil and an eraser; the last is the most important piece of equipment at this stage. Start by writing down how you intend to write
1
12
123
1234
12345
123456
Since you say you have got that to work, it shouldn’t be too difficult. Then work out the differences. Do it bit by bit. And don’t try to write Java nor pseudocode at this stage. Write plain English.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you start off by saying "I need to use nested loops to solve this problem", you're doing it wrong. You start off with a blank page, and say "What do I need to do?".

I think starting off as you did is like saying "I need to use a hammer to drill a hole". Nope. that's not gonna work. You start by saying "I need a 3/8" hole in a wall approx. 2 inches deep. It may have to go through drywall and some lumber. I will not have access to electricity, but can carry stuff where I am working. How should I accomplish this?"

THEN you look in your toolbox for something that can do that - like a cordless screw-drill.
 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:If you start off by saying "I need to use nested loops to solve this problem", you're doing it wrong. You start off with a blank page, and say "What do I need to do?".

I think starting off as you did is like saying "I need to use a hammer to drill a hole". Nope. that's not gonna work. You start by saying "I need a 3/8" hole in a wall approx. 2 inches deep. It may have to go through drywall and some lumber. I will not have access to electricity, but can carry stuff where I am working. How should I accomplish this?"

THEN you look in your toolbox for something that can do that - like a cordless screw-drill.



What is lowercase baba Fred?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic