Skip to Main Content

multidimesnional Arrays

3054158Mar 17 2016 — edited Mar 18 2016

Gurus , I am stuck here ,I've done arrays in my high school but finding this array hard to understand .. All my confusion started with the below e.g from Java tutorial.

class MultiDimArrayDemo {

    public static void main(String[] args) {

        String[][] names = {

            {"Mr. ", "Mrs. ", "Ms. "},

            {"Smith", "Jones"}

        };

        // Mr. Smith

        System.out.println(names[0][0] + names[1][0]);

        // Ms. Jones

        System.out.println(names[0][2] + names[1][1]);

    }

}

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

My  understanding ..this should be creating a matrix of 3x2

row x column

Matrix:

00 01

10 11

20 21

so I think,

00 = Mr.Smith

01 = Mr.Jones

10 = Mrs.Smith

11 = Mrs.Jones

20 = Ms.Smith

21 = Ms.Jones


So this should .."    System.out.println(names[0][0] + names[1][0]);" print  Mr.Smith Mrs.Smith

and this should .. System.out.println(names[0][2] + names[1][1]);   .. [0][2] is not in matrix and [1][1] is Mrs>Jones

So why the output is different .. can some one plz explain where I am going wrong

This post has been answered by Jiri.Machotka-Oracle on Mar 17 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on Apr 15 2016
Added on Mar 17 2016
6 comments
1,374 views