Results 1 to 5 of 5
  1. #1
    ziongio is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default how to pass user input into multi-dimensional arrays

    I am trying to put my user input into a 7-dimension array. each dimension should be used to keep a certain trait of a student. When a user wants to see the info on the student, she/he inputs the student id and all the info is displayed. The info should not be saved to a file, just saved while the program runs.
    I have been trying to solve this for a while. Thanks for the help. :)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I think you want a 2 dimensional array. I could be wrong though, please clarify.

    Do you want an array where each slot is a 7 item array? Or something else?

    Java Code:
    int[][] a = new int[3][7];
    where
    int[0] = int[7]
    int[1] = int[7]
    int[2] = int[7]
    It may honestly be easier to create a class which has all the student data and then work with a 1 dimensional array.

    A 7 dimension array would be extremely challenging to keep track of.

    it would be an array where each slot is a 6 d array, and each slot in the 6 d array would be a 5 d array, and so on, which would be pretty complex.

    Even a 3d array would be quite complex and probably not what you want.

    a 3d array of
    Java Code:
    int[][][] = new int[2][2][2];
    would be
    int[0] = int[][]
    int[0][0] = int[]

  3. #3
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    I agree.

    Using parallel arrays to model your data is a bad idea. Using multidimensional arrays are even worse. Do as suggested and use a class to hold your data instead.

  4. #4
    eXistenZ is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default Solution without a question

    So, would this be the case of someone focusing on coding a solution without thoroughly examining the problem?

    A 7-dimensional array? That should be a clue.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I have a feeling he just misworded it. Im assuming he meant a 2 d array with 7 item arrays, like this:

    Java Code:
    String[][] people = new String[5];
    people[0] = new String[7];
    people[1] = new String[7];
    ...
    people[4] = new String[7];
    But again it would be better to use a class and a single array or arraylist.

Similar Threads

  1. Replies: 4
    Last Post: 08-01-2010, 09:25 AM
  2. Replies: 5
    Last Post: 11-26-2009, 07:01 PM
  3. Multi-dimensional arrays
    By Implode in forum New To Java
    Replies: 1
    Last Post: 09-15-2009, 08:50 AM
  4. [SOLVED] Multi-dimensional arrays
    By thelinuxguy in forum Advanced Java
    Replies: 3
    Last Post: 05-07-2009, 02:52 PM
  5. Replies: 2
    Last Post: 01-07-2008, 07:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •