Results 1 to 4 of 4
  1. #1
    mcnam4119 is offline Member
    Join Date
    Sep 2010
    Location
    Singapore
    Posts
    13
    Rep Power
    0

    Exclamation Printing Two Dimensional Arrays with for loops

    I have been asked to create a program that will print a grid that looks like this:
    0 1 2 3
    1 2 3 4
    2 3 4 5
    3 4 5 6
    And I must do it using for loops. This is the code I have at the moment but I am unsure if it works and I don't think it is complete PLEASE HELP!!

    int twoDimArr[x][y];
    for(int x=0;x<x.length;x++)
    {
    for(int y=0;y<y.length;y++)
    {

    System.out.print(twoDimArr[x][y])

    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    but I am unsure if it works
    Does it compile?
    Does it execute?
    Do you get any output?
    Is the output what you want?

    One thing you need is to print a newline character at the end of every line to move the print out to the next line.

    Also the array you are printing out has the initial values of 0.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default

    Also, int doesn't have a length.

    To get better help sooner, post the code you already have in the form of an SSCCE.
    SSCCE : Java Glossary

    db

    edit You probably need this too
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Last edited by DarrylBurke; 10-04-2010 at 09:44 AM.

  4. #4
    mcnam4119 is offline Member
    Join Date
    Sep 2010
    Location
    Singapore
    Posts
    13
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 08-01-2010, 09:25 AM
  2. A few questions about arrays and loops
    By Jamison5213 in forum New To Java
    Replies: 1
    Last Post: 12-22-2009, 05:59 AM
  3. dynamic two dimensional arrays?
    By dinosoep in forum New To Java
    Replies: 4
    Last Post: 12-05-2009, 06:12 PM
  4. Multi-dimensional arrays
    By Implode in forum New To Java
    Replies: 1
    Last Post: 09-15-2009, 08:50 AM
  5. [SOLVED] Multi-dimensional arrays
    By thelinuxguy in forum Advanced Java
    Replies: 3
    Last Post: 05-07-2009, 02:52 PM

Tags for this Thread

Posting Permissions

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