• 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 62809
203
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!