codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  2 Dimensional Array  maig at 21:51 on Sunday, April 30, 2006
 

Hello,

I'm trying to write two methods, one will tell me how many rows in the array and one will tell me how many columns in the array. I'm not sure how to do this.

Signature of method for number of rows:

public int numOfRows()
{

}

I also need to write a method for number of columns:

public int numOfColumns()
{

}

What I'm used to doing is using the .length method but that only gives me the number of rows in the array. It would look like:

return grid.length; (where grid is the name of the array)

Thanks,
Maig

  Re: 2 Dimensional Array  crwood at 22:24 on Sunday, April 30, 2006
 


public class Test
{
static int[][] testArray = new int[7][4];

public static void main(String[] args)
{
System.out.println("rowCount = " + numberOfRows() + "\n" +
"colCount = " + numberOfColumns());
}

private static int numberOfRows()
{
return testArray.length;
}

private static int numberOfColumns()
{
return testArray[0].length;
}
}


  Re: 2 Dimensional Array  maig at 22:59 on Sunday, April 30, 2006
 

thank you!








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  jslider - paint track
•  Re: convert minutes into hours and minutes
•  File handle problem
•  Link Capture, help needed
•  Re: java app auto web update..
•  IE Only comeback
•  ` Error Code 64: Host not available ` - Error when accessing ASP Appln
•  Re: dynamic crystal report generation
•  Launch an app remotely through a website


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007