This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to handle rows/columns in arrays  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to print a 2-d array of powers, but I'm having trouble getting my head around the idea of columns and rows.
So if I'm correct, is my inner loop assigning values in the array for columns, and my outer for loop is for the rows?
Or should I have a separate array for each row of the table?
Thanks for any help!



is printing:


It should be printing:

[1.0 1.0 1.0 1.0 ]
[2.0 4.0 8.0 16.0 ]
[3.0 9.0 27.0 81.0 ]
[4.0 16.0 64.0 256.0 ]
[5.0 25.0 125.0 625.0 ]
[6.0 36.0 216.0 1296.0 ]
[7.0 49.0 343.0 2401.0 ]
[8.0 64.0 512.0 4096.0 ]
[9.0 81.0 729.0 6561.0 ]
[10.0 100.0 1000.0 10000.0 ]
 
Ranch Hand
Posts: 1609
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the inner loop the j begins at 0.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While Akhilesh has pointed you where the problem lies, you can just add one when you find the pow and keeping the loop and the value of j as is.
 
Marshal
Posts: 61718
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to look at the conventions about the Math#pow() method. Particularly what x to the power of 0 is.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!