String Statement

-1

I'm declaring a variable like this:

private String[,] soloMarciano;

Can you do this in Java? Well, I need to read two X and Y positions.

    
asked by anonymous 08.01.2016 / 21:40

2 answers

3

What you are asking is called two-dimensional arrays or arrays, I found this link a very broad explanation of how they work.

But in short, you can declare a two-dimensional array 2 by 4 (8 elements) as follows:

String[][] xy = new String[2][4];
    
08.01.2016 / 22:27
0

You can declare and initialize the two-dimensional string in this way:

private string[][] soloMarciano = {{"a","b"},{"c","d"}};

or declare and initialize it like this:

private string[][] soloMarciano;

soloMarciano[0][0] = "a";

soloMarciano[0][1] = "b";

soloMarciano[1][0] = "c";

soloMarciano[1][1] = "d";

To read the letter "a", you can use System.out.println([0][0]);

The letter "b", use System.out.println([0][1]);

The letter "c", use System.out.println([1][0]);

The letter "d", use System.out.println([1][1]);

    
09.01.2016 / 00:34