• 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

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: 60168
188
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!