Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Requesting help with solving a problem.

 
Mack Grill
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm trying to determine java expression evaluates the number of columns

Given array T below,
double[][] T = new double[3][5];

what Java expression evaluates the number of columns , and what would this expression return for T?
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't really have two dimensional arrays. Rather, it has arrays of arrays. What that means is, if we assume you mean the first index is the 'number of rows' then the number of 'columns' (the second length of the inner array) can vary from row to row. A common approach to get 'the number of columns' would be to get the length of the array at T[0] (the length of the first array indexed in T).


Mack Grill wrote:
...and what would this expression return for T?


What does it give you when you run it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic