This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Nested Loops Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Nested Loops Pattern" Watch "Nested Loops Pattern" New topic
Author

Nested Loops Pattern

Melissa Ann
Greenhorn

Joined: Feb 20, 2013
Posts: 1
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 )
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39095
    
  23
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.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11356
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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?


~ Mansukh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested Loops Pattern