Results 1 to 3 of 3
  1. #1
    matin1234 is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default about two dimensional array

    Hi
    I can not get why these lines are equal too each other!!! thanks
    Java Code:
    Y[i][i+1] = Y[i][i] + 3;

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Uhm, there is only one line there.

    Say i = 5, then what that line is doing is setting the element at [5][6] to the value of the element at [5][5] plus 3. I really don't know what you don't understand about it.

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by matin1234 View Post
    I can not get why these lines are equal too each other!!! thanks

    because with i + 1 you're referencing an other element then with i. look at the following code:

    Java Code:
    public class TestClass {
    
    	public static void main(String[] args) {
    		
    		String[][] Y = new String[2][2];
    		
    		Y[0][0] = "String[0][0]";
    		Y[1][0] = "String[1][0]";
    		
    		int i = 0;
    		
    		System.out.println(Y[i][i]); // guess the output
    		System.out.println(Y[i + 1][i]); // guess the output
    
    	}
    }

    hope you understand.

Similar Threads

  1. 2 dimensional array help!
    By ber1023 in forum New To Java
    Replies: 9
    Last Post: 01-02-2011, 12:29 AM
  2. Multi-dimensional array
    By VinTiger in forum New To Java
    Replies: 22
    Last Post: 03-01-2009, 06:51 AM
  3. two-dimensional array
    By kHim in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 07:21 PM
  4. Multi dimensional Array
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 03:34 PM
  5. How to initialize a two dimensional Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:48 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
  •