-1
I’m declaring a variable like this:
private String[,] soloMarciano;
Can you do this in Java? Because I need to read two X and Y positions.
-1
I’m declaring a variable like this:
private String[,] soloMarciano;
Can you do this in Java? Because I need to read two X and Y positions.
3
What you want is called two-dimensional matrices or vectors, I found in this link a very broad explanation of their functioning.
But in short, you can declare a 2-by-4 (8-element) two-dimensional array as follows:
String[][] xy = new String[2][4];
It is also important to point out in your answer, that the size of the vector is defined before its use, because its size is not dynamic as in the case of Arraylist
0
You can declare and initialize the two-dimensional string this way:
private string[][] soloMarciano = {{"a","b"},{"c","d"}};
or declare and initialize it so:
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 a 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]);
Browser other questions tagged java variables
You are not signed in. Login or sign up in order to post.
Can you explain better what you want to do? What result you expect?
– Pablo Almeida