Multi-dimensional arrays in Java

Discussion in 'Java' started by pradeep, Aug 11, 2006.

  1. afredi786

    afredi786 New Member

    Joined:
    Jan 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Sir Can yo Kindly tell me how to multiply two arrays. or you can say if we want to multiply numbers in two string and save result in another string.how will i will be able to do it.

    e.g string1= "3298733333233121215455"
    string2= "98234234239847239847239482"
    how can i multiply them and save them in string3.
     
  2. Harishgp

    Harishgp New Member

    Joined:
    Feb 15, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    Can someone tell me how to generate general "n dimensional arrays"?. (i.e) I am given the number of dimensions and the length along each dimension as arguments to a function , I need to generate such an array in that function. All I can tell about the number of dimensions before hand is it will be less than 20. (Assume the lengtth along dimensions are such that the number of elements don't go beyond memory).


    Thanks,
    Harish
     
  3. Bearcat20

    Bearcat20 New Member

    Joined:
    Apr 25, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am studying for my Programming 1 final and I am having a little trouble with this problem on my study guide. Any assistance would be greatly appreciated. The problem is as follows.

    Show how to declare a 2 dimensional array of integer values. This array should have 5 rows and 300 columns. Next, show the code necessary to fill this array with random values ranging from 0 up to 99 (including both 0 and 99). Finally, show the code necessary to sum up the values in each column and display the sum of each on the screen.
     
  4. srkanth_rks

    srkanth_rks New Member

    Joined:
    May 20, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    MATLAB scans column-wise the input matrix and writes them column-wise into the new matrix of specified matrix. Now i need to do that in Java, not a generic reshape, but for some specific cases. One of them is to transform a 1D array a[50400] into this 7D array c[2][12][4][5][5][7][3]. please, suggest how to do this.
     
  5. marcox4

    marcox4 New Member

    Joined:
    Aug 14, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Would anybody know how to get user input into a muti-array in netbeans, from two diffrent textfields?
     
  6. shivika

    shivika New Member

    Joined:
    Oct 27, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    How can i implememt a gauss jacobi iteration in java programming language...using multi dimentional array and asking the user to enter all the details(No.of row, columns, the elements...).

    thanks and regards....
     
  7. shivika

    shivika New Member

    Joined:
    Oct 27, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hello,
    im having problem to implement a gauss jacobi iteration in java...
    can som1 please help me....
     
  8. rameshb

    rameshb New Member

    Joined:
    Dec 10, 2010
    Messages:
    35
    Likes Received:
    1
    Trophy Points:
    0
    Thank you pradeep for uploading it in this forum . the example code are superb.. chow
     
  9. yellowscooter

    yellowscooter New Member

    Joined:
    Dec 15, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Delhi
    Home Page:
    http://www.friendsofbooks.com/store/used-books
    Multi-dimensional arrays are powerful constructs in Java. However, most of the times its better to an VO class, and store these objects in a List or a Map. This approach is more object oriented, and much easier to implement and understand.
     
  10. rameshb

    rameshb New Member

    Joined:
    Dec 10, 2010
    Messages:
    35
    Likes Received:
    1
    Trophy Points:
    0
    thank you for submitting this code ...
     
  11. mikkko

    mikkko New Member

    Joined:
    Jul 24, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Pilipinas
    pradeep, can you help me with this please

    Create an addressbook program that asks for user input and could store until 15 entries using multi-dimensional array.

    Note: Use JOptionPane or BufferedReader for the user input and program output.

    Here is the sample format:
    Name : Florence Santiago
    Tel# : 735-1234
    Address : Manila

    Name : Joyce Jimenez
    Tel# : 983-33333
    Address : Quezon City

    Name : Becca Singson
    Tel# : 456-12345
    Address : Pasig City

    The number of entries to be displayed will be based on the number of addressbook entries inputted by the user.
     
  12. finedesignnyc

    finedesignnyc New Member

    Joined:
    Jul 26, 2011
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Does all of this work well with any version of Java?
     
  13. weebo123

    weebo123 New Member

    Joined:
    Oct 21, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi Pradeep,

    I have recently decided to do some Android Game Development using Java. However I am having the below issue:

    I am looking at creating a 2D birdseye view of a map where the user is basically working there way through it.

    Is there a way that I can create the whole map in 1 go and store it somewhere. Then simply only display a certain section of that map during gameplay.
    e.g map size =100 x 100 but user can only ever see 5x5 (which is zoomed tin to use up 70% of the screen).

    I am thinking of using a 2d java array of bitmaps and using this array to draw onto a canvas. However, I am not entirly sure how to do this, as i would also like that every time the player moves their character forward a step, the next section of the canvas is drawn (always 5 x 5 regardless of whether they go left, right, straight or back).

    Any help as to how I could go about doing this would be much appreciated.

    Thanks
     
  14. mjshaheed

    mjshaheed New Member

    Joined:
    Dec 20, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Programmer
    Location:
    Iowa City
    Hi Pradeep,

    First of all sorry for digging up the old thread! I am learning Java...

    I have a question as to how many objects are created in the following code:

    Code:
    int[][] a2 = new int[10][5];
    You said "This allocates an int array with 10 rows and 5 columns. As with all objects, the values are initialized to zero (unlike local variables which are uninitialized).

    This actually allocates 6 objects: a one-dimensional array of 5 elements for each of the rows, and a one-dimensional array of ten elements, with each element pointing to the appropriate row array
    ."

    Aren't 10 object(references) created here, each for one row...a[0]....a[9]? Again sorry if i am mistaken!!!

    Thanks,
    Shahul
     
  15. lis

    lis New Member

    Joined:
    Mar 27, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    How to do an array in java?
    I need to make an array that reads the latitude and longitude.
    A for loop that reads into all of them into the array.

    latitude Longitude
    27.03434 -73.3423
    27.02342 -73.2466
    ........... ...........
    ........... ...........
    ...this continues on
    So I guess I need an array to read in the rows from the file without knowing the exact number of rows in the file.

    double[][] numbers = new double [][];

    for (double row = 0; row < numbers.length; row++)
    {
    for (double col = 0; col < numbers[row].length; col++)
    System.out.println(numbers[row][col]);

    Can you please help me. This won't work.


    I have tried many ways, but can't figure it out.
    There are two columns, but the rows of the files are a lot, and I need the array to read the numbers in the rows that are available into the array
     
  16. mfred90

    mfred90 Banned

    Joined:
    Mar 28, 2012
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    To Create two dimensional array dunamically.I know the number of columns. but the number of rows are chnaged dynamically. I have tried array lisy. But it storing single value. so what should I Do ?
     
  17. cuongedvhp

    cuongedvhp New Member

    Joined:
    Jun 14, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    There are two ways to implement 2-dimensional arrays. Many languages reserve a block of memory large enough to hold all elements of the full, rectangular, array (number of rows times number of columns times the element size). Java doesn't do this. Instead Java builds multi-dimensional arrays from many one-dimensional arrays, the so-called "arrays of arrays" approach. [C++ supports both styles.]
     
  18. Healthcare

    Healthcare Banned

    Joined:
    Jun 14, 2012
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    for (int r=0; r<a2.length; r++) {
    for (int c=0; c<a2[r].length; c++) {
    System.out.print(" " + a2[r][c]);
    }

    Hi, Pradeep
    I have a doubt in for loop. Can you explain why you have taken the statement "c<a2[r].length". I am little bit confused. please help.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice