Results 1 to 9 of 9
  1. #1
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Printing 2 2D arrays next to each other

    Hello everyone, I'm making a battleship game, and it looks great already. I'm almost done but I'm stuck with my 2D array. I have 2 2D arrays (each one is a field where you can place ships on). I want to place them next to each other. Now I have to place them under each other. Anyone have a suggestion on how to do this?

    thx in advance

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default Re: Printing 2 2D arrays next to each other

    Hi Matthieu,

    I'm assuming this presented on the console as opposed to a GUI. As these are presented one over the other I presume you are looping through one array before looping through the next. Instead, try printing a line of each board before moving moving to the next.

    Regards.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Printing 2 2D arrays next to each other

    Java Code:
    for each row
       for each column on array 1
          print value
       inset some form of divide character(s)
       for each column on array 2
          print value
    Something like that.
    Your choice of what to use as a divide, but '<space>|<space>' seems reasonable to me.

    ETA: In other words, what Ronin said...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Printing 2 2D arrays next to each other

    Can't I do this with a stringBuilder?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Printing 2 2D arrays next to each other

    The logic won't be any different.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Printing 2 2D arrays next to each other

    Printing 2 2D arrays next to each other-schermafbeelding-2013-02-14-om-16.18.40.png

    This is my field, now i want the same field next to it, it don't know how I can do that with the code above :/

    So it has to be like this:
    Printing 2 2D arrays next to each other-schermafbeelding-2013-02-14-om-16.21.42.png
    Last edited by Matthieu105; 02-14-2013 at 05:22 PM.

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Printing 2 2D arrays next to each other

    Reread Ronin's and Tolls' replies. They've told you how to do it.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Printing 2 2D arrays next to each other

    Don't get it how to do it,

  9. #9
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Printing 2 2D arrays next to each other

    Honestly, Tolls posted perfect pseudo code. Did you understand that? If not, what is the question?
    We certainly won't provide the ready made code for you, but we'll gladly assist you writing it yourself.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Printing multiple arrays help...
    By Toffer_15 in forum New To Java
    Replies: 8
    Last Post: 01-24-2013, 10:35 PM
  2. Error while printing out arrays
    By cjgarcia in forum New To Java
    Replies: 1
    Last Post: 05-03-2012, 01:34 AM
  3. Printing multiple arrays in 1 dialog box
    By turbopenguin in forum New To Java
    Replies: 9
    Last Post: 04-19-2012, 09:18 AM
  4. Printing Two Dimensional Arrays with for loops
    By mcnam4119 in forum JCreator
    Replies: 3
    Last Post: 10-06-2010, 06:27 AM
  5. Printing value of boolean arrays
    By myst in forum New To Java
    Replies: 7
    Last Post: 06-02-2010, 09:44 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
  •