This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Nested loops  RSS feed

 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am in a beginners java class and I just cant figure out how to do these two nested loops can anyone help

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8
3 4 5 6 7
4 5 6
5

and

    1
  212
32123
4321234
32123
   212
     1

thank so so much!
 
Marshal
Posts: 60096
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We don't hand out complete answers, but if you show us what you have got so far, we'll be happy to comment on it.
 
Ryan Arroyo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I am on my phone right now I will show what I have so far
 
Campbell Ritchie
Marshal
Posts: 60096
188
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So hw far have you got with it? Writing that sort of loop is often awkward; it is better to start with something simpler and buld up the application.
Try printing

1

then

1 2

then

1 2 3

etc. That will be a start.
 
Marshal
Posts: 6008
415
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

requirement wrote:1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8
3 4 5 6 7
4 5 6
5


Also write down on a piece of paper what pattern you notice here. What rules are being applied. That should be simple to work out with a pencil on a piece of paper.
 
Ryan Arroyo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this is what i have so far for the pyramid the other one It keeps printing out only 9

Moderator edit: added code tags
 
Ryan Arroyo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and this is what i have for the other one

 
Ryan Arroyo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UPDATED


prints

Method 15:
123456789
12345678
1234567
123456
12345
End Method 15
 
Sheriff
Posts: 5116
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks a lot like you're guessing.  Not the best way to write a program.

Hint: what is the relationship between the rows and columns?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!