Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: 2 dimensional array storing help!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 2 dimensional array storing help!

    My goal is to take the string and place each individual character in a two dimensional array. Here is what I have so far...

    The string totalMaze is:
    oooooooo#S#ooooooo#oo##oooo#ooo#oo#oo$ooo######ooo oooooo


    char [][] array = new char [numberOfRows][numberOfColumns];

    for (int row = 0; row < numberOfRows; row++)
    {

    for (int col = 0; col < numberOfColumns; col++)
    {

    array[row][col] = totalMaze.charAt(?????????????);
    }

    }



    I tried another for loop within the col loop, like for (int i = 0; i < totalmaze.length();i++)


    the result is:

    oooooooo
    oooooooo
    oooooooo
    oooooooo
    oooooooo
    oooooooo
    oooooooo

    and I need it to be:

    oooooooo
    #S#ooooo
    oo#oo##o
    ooo#ooo#
    oo#oo$oo
    o######o
    oooooooo

    I can't figure out what to put in the charAt method to make it work! Please help, very frustrated thanks. Will post more info if needed.



    ALSO...The goal of the project is to develop this maze with S as the start, o's as "roads" and #'s as "walls". $ is the end.
    We need to use a recursive method to find the treasure.

    I need help developing the algorithm for finding the treasure. I need to check the neighbors, but not diagonals and mark with an X if it is not the treasure so that I don't check it again. Just hard to wrap my head around
    Last edited by jts0541; January 31st, 2012 at 02:14 PM.


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: 2 dimensional array storing help!

    Think about how a two dimensional array works, if you make a row then make columns within that specific row, what happens?

    You don't need a third loop, and you're loop is in the right spot. Think about you're string. If you're dealing with a four character string ( let's say the word "Java") and you separate it into a two by two dimensional array. Row 1 Column 1 is the letter J, while Row 2 Column 1 is the letter A. Look at indexes the characters you're printing are. Tip : You're program needs to know how to adjust the index it needs to print for the next row.

    Alright so I'm awful at recursion, but I would try and separate the recursive function into two smaller recursive functions. Think about the relationship between the neighbors. Hint: The left neighbor is -1 column away and the right neighbor is +1 column away.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 2 dimensional array storing help!

    Yah i think I understand how a 2 dimensional array. But from your java array wouldn't that look like
    J
    a
    v
    a

    Take the string javaprogramming for example I need it to be like

    javaprog
    ramming

Similar Threads

  1. Help with storing objects in array? :(
    By spoonemore11 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 2nd, 2011, 05:28 PM
  2. Single Dimensional Array Help!
    By Allicat in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 15th, 2011, 12:01 PM
  3. help w/ storing/scanning numbers in two dimensional arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 1st, 2010, 11:56 PM
  4. 2 dimensional array alternative ???
    By zeeshanmirza in forum Java SE APIs
    Replies: 1
    Last Post: February 23rd, 2010, 06:18 PM
  5. Reading .txt and storing into an array
    By vluong in forum Collections and Generics
    Replies: 1
    Last Post: January 4th, 2010, 02:07 PM