1. Definition of two-D arrays
2. Memory space for two-d arrays
//3. Irregular arrays
The output should be placed inside the loop, and the error will be on the outside.
Hit debug to determine the relationship between two-dimensional arrays
Now the program loops between 7 and 8 lines
--------------------------------------------------------------------------------------------------------------- ---------------------
And then go through an intermediate stage
And then continue
One until
It's over.
Two-dimensional array memory structure
Irregular two-dimensional arrays
- 1. Definition of two-D arrays
- 2. Memory space for two-d arrays
- 3. Irregular arrays
- Package Me.array;
- Public class array2demo{
- public static void Main (string[] args) {
- //Create and print irregular two-dimensional arrays
- int arr[] [];
- arr=New int[3][]; Now the description is an irregular array
- arr[0]=new int[]; Arr[0] point to another array
- arr[1]=new int[3];
- arr[2]=new int[4];
- //Assigned value
- For (int i=0;i<arr.length;i++) {
- For (int j=0;j<arr[i].length;j++) {
- Arr[i][j]=j;
- }
- }
- //Output
- For (int i=0;i<arr.length;i++) {
- For (int j=0;j<arr[i].length;j++) {
- System.out.print (arr[i][j]+"");
- }
- System.out.println ();
- }
- /* Output Result:
- 0 1 2 3 4 5 6 7 8 9
- 0 1 2
- 0 1 2 3
- *///
- }
- }
[Java]View PlainCopy print?
- 3. Write a method that returns a double-type two-dimensional array, which is obtained by parsing the string argument.
- such as "1,2;3,4,5;6,7,8"
- d[0,0]=1.0 d[0,1]=2.0 d[1,0]=3.0 ....
- Package me.parser;
- Public class teststring{
- public static void Main (string[] args) {
- //1. Splitting the split with a string (";") into three array of strings
- //2. Splitting Split (",")
- //Declare a two-dimensional array to fit the decomposed characters
- String s="1,2;3,4,5;6,7,8";
- //Split () method to decompose
- String[] Sfirst=s.split (";");
- String[][] word=new string[sfirst.length][];
- int flag=0;
- For (int i=0;i<sfirst.length;i++) {
- //Print out the separated
- //system.out.println (Sfirst[i]);
- / * This statement outputs
- The
- 3,4,5
- 6,7,8
- *///next in accordance, separate them into a one-dimensional array
- String[] Ssecond=sfirst[i].split (",");
- //~ System.out.println (ssecond.length);
- //~/* Output:
- //~ 2
- //~ ---------------------------------
- //~ 3
- //~ ---------------------------------
- //~ 3
- //~ ---------------------------------
- //~ *///The length of the one-dimensional array is different each time Ssencond
- word[i]=New String[ssecond.length]; This step determines the length of rows for each row of an irregular array
- //Assign a value to this array
- For (int j=0;j<ssecond.length;j++) {
- WORD[I][J]=SSECOND[J];
- }
- System.out.println ("---------------This is the first" + (i+1) +"secondary cycle-------------------");
- }
- //Output two-dimensional array
- System.out.println ("Output two-dimensional array-------------------");
- For (int i=0;i<word.length;i++) {
- For (int j=0;j<word[i].length;j++) {
- System.out.print (word[i][j]+"");
- }
- System.out.println ();
- }
- /* Results:
- ---------------This is the 1th cycle-------------------
- ---------------This is the 2nd cycle-------------------
- ---------------This is the 3rd cycle-------------------
- Output two-dimensional array-------------------
- 1 2
- 3 4 5
- 6 7 8
- Output two-dimensional array-------------------
- *///
- }
- }
Operation of a two-dimensional array in Java