Results 1 to 14 of 14
  1. #1
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Unhappy Multi-dimensional array program-help!

    This is my next challenge:
    Create a program that generates a 10x10 table. Your program should fill the table with random integers between 0 and 9. Display the contents of your table on the screen as a 10x10 grid. AFTER the numbers have been generated and displayed on the screen, calculate and display the total of the 100 numbers generated.
    I must use multi-dimensional arrays to create this program and I have no knowledge on them at all, so i need to learn some more about them and get my program started, all i understand is the outline for the table i need:
    Java Code:
    public static void main (String[] args)
        {
            c = new Console ();
            //create a 10*10 table
            int table[] [];
            table = new int [10] [10];
            //create a loop to put the random values of 0 to 9 in
        }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    What happens when you compile your code?

    If there are compiler messages that you can't understand, post the message exactly as it appears. (Make sure you have your textbook/notes etc handy so you are familiar with any usage examples you have seen.)

  3. #3
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    nothing happens when i click run, i have no idea where to go next because i have no content/textbook for multi dimensional arrays so im very lost as to creating this program

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    nothing happens when i click run
    So, are you saying your code compiles? In that case, post the code you are using.

  5. #5
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    Yes the only code i have runs but nothing appears on the output screen and obviously its nowhere near finished:
    Java Code:
    c = new Console ();
            //create a 10*10 table
            int table[] [];
            table = new int [10] [10];

  6. #6
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    @pbrockway2, he already did. its the unfinished code above.

    @bob: found something for ya. Multi-dimensional arrays in Java

    edit:
    why are you using console in the code above?
    Last edited by angryboy; 03-06-2009 at 11:50 PM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Quote Originally Posted by angryboy View Post
    @pbrockway2, he already did. its the unfinished code above.
    My mistake - I thought we were dealing with java.io.Console here.

  8. #8
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    thanks for the site link, but im still confused as to how to fill the 10 by 10 table with random numbers and then print it

  9. #9
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    Quote Originally Posted by bobmasta5 View Post
    Yes the only code i have runs but nothing appears on the output screen and obviously its nowhere near finished:
    Java Code:
    c = new Console ();
            //create a 10*10 table
            int table[] [];
            table = new int [10] [10];
    nothing is output because you don't output anything.

  10. #10
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    yes i know that....but once again im confused as what to do next

  11. #11
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    access each individual element and assign it a random value. read angryboy's link for all the info you need for using a multi-dim array, then search out how to get random numbers

  12. #12
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    This is what i now have but i still have a few errors but not sure how i can fix them:
    Java Code:
    public static void main (String[] args)
        {
            c = new Console ();
            //create a 10*10 table
            int table[] [];
            table = new int [10] [10];
            //declare a value that will make a random number between 0 and 9
            int randomInt = 0;
            randomInt = ((int) (Math.random () * 9)) + 1;
            //create a loop to put the random values of 0 to 9 in
            int i, j;
            //two loops, i for the rows
            for (i = 0 ; i < 10 ; i++)
            {
                table [i] [0] = randomInt;
            }
            //second loop, j for the columns
            for (j = 0 ; j < 10 ; j++)
            {
                table [0] [j] = randomInt;
            }
            //every element is assigned the random integer
            //print the table on the output screen
            c.println (table [i] [j] + " ");
    
        } // main method
    } // MultiDimensionalTable class

  13. #13
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    any ideas? I pretty sure its close to complete!

  14. #14
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    nope, you are way off.
    another thread has been started here:
    noob: two-dimension array

    consider this one closed.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Replies: 7
    Last Post: 09-27-2011, 12:29 AM
  2. Multi-dimensional array
    By VinTiger in forum New To Java
    Replies: 22
    Last Post: 03-01-2009, 07:51 AM
  3. Multi dimensional Array
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 04:34 PM
  4. Replies: 2
    Last Post: 01-07-2008, 08:45 PM
  5. Help with array multi-dimensional
    By barney in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:00 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
  •