Results 1 to 3 of 3

Thread: Array Help

  1. #1
    bluegreen7hi is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default Array Help

    Hi, I have an assignment to make a console-based Tic Tac Toe game in Java. I first need to create an array of positions, from position 0 to 9. I'm familiar with arrays somewhat, but what I don't know is how to make it output my array in the form of the Tic Tac Toe matrix, like this:

    0 1 2

    3 4 5

    6 7 8


    I've been looking all over and I can't find any tutorials on how to make it output like this. I know it's something stupid and simple that I'm missing, but I can't seem to figure it out. Thanks in advance.

  2. #2
    frea is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default

    i don't know java at all, but in pseudocode it would be

    Java Code:
    for i = 1 to 10 do
       print ( i - 1 );
       if i mod 3 == 0 then
          print( newline );
    mod -> modulo operator.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In Java it's look like this.

    Java Code:
            for( int i = 0; i < 9; i++ ){
                System.out.print(i + " ");
                if( i % 3 == 2 ){
                    System.out.println();
                }
            }

Similar Threads

  1. can anyone help... 2d Array
    By Mark1989 in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 08:59 PM
  2. Would appreciate your help with 2d Array..
    By cloudkicker in forum New To Java
    Replies: 1
    Last Post: 02-11-2008, 02:34 PM
  3. 2D array
    By bluekswing in forum New To Java
    Replies: 2
    Last Post: 01-15-2008, 05:57 PM
  4. Bounded Array
    By bugger in forum New To Java
    Replies: 4
    Last Post: 01-04-2008, 09:41 AM
  5. Help with Array
    By susan in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:32 AM

Posting Permissions

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