Beginning Java 2d Arrays

This is a discussion on Beginning Java 2d Arrays within the Tech Board forums, part of the Community Boards category; I have a Java 2d array for numbers, a 10x10 matrix, but how can I go about returning the postioning ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    104

    Post Beginning Java 2d Arrays

    I have a Java 2d array for numbers, a 10x10 matrix, but how can I go about returning the postioning of a key value (searching for it) and searching for specific positions (using the two coordinates) to put in a value?

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    might be better if you went to a Java board and asked this

    But i think what you're asking should work something like this:

    Code:
    int[][] array=new int[20];
    for(int a=0;a<20;a++)
    	 array[a]=new int[20];
    then you just do array[3][3] to access the position 4, 4 in the array

    or something like that, i haven't coded with Java for a while now (in my java class for my semester test i actually wrote a C++ program, lol)

    but yah, like i said, you'll get much better answers from a Java forum
    Last edited by jverkoey; 05-27-2004 at 08:29 PM.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    104
    i know how to return the pos of a value in a normal 1d array, as it just one integer, but I cant return two numbers for a 2d array...can I?

    know any good Java forums?

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    http://www.google.com/search?hl=en&i...&q=java+forums

    should be able to find some good ones there ^^

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    unlike C++, you can dynamically initialize a multi-dimensional array in java by just specifying the args after new...

    ie) .. new int[4][SIZE][otherDynamicVariable];

    Hexxx, you seem to have a misconception of what a multi-dimensional array is, you cant return more than one number from it. Its just like a table of single values (2D array that is)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with 2d Int Arrays
    By Voondebah in forum C Programming
    Replies: 2
    Last Post: 02-25-2009, 11:36 PM
  2. 2D Array's, assigning chars.
    By gman89 in forum C Programming
    Replies: 9
    Last Post: 04-27-2008, 12:03 AM
  3. 2D arrays programming, please help
    By mfskratch in forum C Programming
    Replies: 4
    Last Post: 11-01-2007, 01:41 PM
  4. Having problems with 2d arrays
    By newy100 in forum C++ Programming
    Replies: 4
    Last Post: 01-04-2004, 11:46 AM
  5. pointers to 2d arrays
    By Diamonds in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2002, 06:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21