Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15
  1. #11

    what do you really want to know about java array? concept of array? or just java syntax?

  2. #12
    something related to datastructure in java...more on array man gud cya and methods

  3. #13
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018
    Quote Originally Posted by skeptic_rob View Post
    something related to datastructure in java...more on array man gud cya and methods
    heheh klaro au galibog pa gyud ka asa magsugod... masnindot bai code na diretso... basta dili ka kasabot the essense of typing code will give you confidence and you will definitely learn something.

  4. #14
    Hope this will help....you can try it as you please...

    ================================================== ============
    //////////////////////////////////////////////////////////////////////////////////
    // This code snippet illustrates a 5x5 two dimensional array. The values//
    // of the array are presented in a table. //
    /////////////////////////////////////////////////////////////////////////////////

    //defines the number of rows and columns
    int rows = 5;
    int columns = 5;


    // initialize the array
    String [][] array = new String[rows][columns];

    /**
    * Let's stores values into the array(in this case the value is a string).
    * The stored values represents the indexes of the array where
    * the value is stored.
    *
    * e.g. array[0][1] has a stored string "[0][1]" this means that
    * at row 0 column 1 the value is "[0][1]".
    *
    * furthermore,
    * array[0][1] == "[0][1]"
    */

    //loops the rows
    for(int x=0; x<array.length; x++)
    {

    //loops the columns
    for(int y=0; y<array.length; y++ )
    {

    //store the string value to the array
    array[x][y] = " ["+x+"]["+y+"]";
    }

    }

    /**
    * Let's display the string we stored in the array. The loops below
    * traverse the array row by row.
    */

    //prints the column heading
    System.out.println(" 0 1 2 3 4");

    //traverse the rows
    for(int x=0; x<array.length; x++)
    {

    //prints the row heading
    System.out.print(""+ x + " ");

    //traverse the columns
    for(int y=0; y<array.length; y++ )
    {

    //prints the value in columns
    System.out.print(""+array[x][y]);
    }

    //prints a next line for the next row
    System.out.print("\n");
    }

    ========================================

    -----0-----1-----2-----3-----4----
    0 [0][0] [0][1] [0][2] [0][3] [0][4]
    1 [1][0] [1][1] [1][2] [1][3] [1][4]
    2 [2][0] [2][1] [2][2] [2][3] [2][4]
    3 [3][0] [3][1] [3][2] [3][3] [3][4]
    4 [4][0] [4][1] [4][2] [4][3] [4][4]

  5. #15
    You can put arrays this way...imagine a locker with numbers. like this

    [0][0] [0][1] [0][2] [0][3] [0][4]
    [1][0] [1][1] [1][2] [1][3] [1][4]
    [2][0] [2][1] [2][2] [2][3] [2][4]
    [3][0] [3][1] [3][2] [3][3] [3][4]
    [4][0] [4][1] [4][2] [4][3] [4][4]

    each pair of numbers represents one locker. if you store a thing, example a "ball", into locker number [1][1]...in java it would be like...

    array[1][1] = "ball" ;

    when you want to get the "ball", you get it from locker [1][1] because it is where you stored it. In java, this would be...

    String str = array[1][1];

    the value of str is "ball".

    so if you will have multi dimensional arrays...the same concept follows. you can treat the indexes as address of your value.

  6.    Advertisement

Page 2 of 2 FirstFirst 12

Similar Threads

 
  1. java - stack() problem
    By akocdiego in forum Programming
    Replies: 12
    Last Post: 07-08-2013, 10:43 PM
  2. Replies: 16
    Last Post: 04-21-2012, 11:26 PM
  3. Help in java. Arrays
    By jairoh_ in forum Programming
    Replies: 25
    Last Post: 02-03-2012, 07:48 PM
  4. java problem..
    By wongfeihong in forum Programming
    Replies: 81
    Last Post: 09-26-2010, 10:56 AM
  5. Got Java, PHP, C, MySQL problem?
    By abstracted in forum Programming
    Replies: 11
    Last Post: 06-25-2010, 09:36 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
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top