As shown below:
//Define two-dimensional array writing method 1 class numthree{public static void main(String[] args){float[][] numthree; //Define a 2-dimensional array of float type numthree=new float[5][5]; //Assign it the space size of 5 rows and 5 columns numthree[0][0]=1.1f; //Use subscript index to access 1 row and 1 column = 1.1numthree[1][0]=1.2f; // 2 rows and 1 column = 1.2numthree[2][0]=1.3f; // 3 rows and 1 column = 1.3numthree[3][0]=1.4f; // 4 rows and 1 column = 1.4numthree[4][0]=1.5f; // 4 rows and 1 column = 1.4numthree[4][0]=1.5f; // 5 rows and 1 column = 1.5System.out.println(numthree[0][0]); //Print new line output System.out.println(numthree[1][0]); System.out.println(numthree[2][0]); System.out.println(numthree[3][0]); System.out.println(numthree[4][0]);}} //Define two-dimensional array writing method 2. Define the space size at the same time. class numfour{public static void main(String[] args){ short[][] numfour=new short[5][8]; //Define an array of short type and allocate the space size of 5 rows and 8 columns. numfour[0][7]=10; numfour[1][6]=20; numfour[2][5]=30; numfour[3][4]=40; numfour[4][3]=50; System.out.println(numfour[0][7]); System.out.println(numfour[1][6]); System.out.println(numfour[2][5]); System.out.println(numfour[3][4]); System.out.println(numfour[4][3]);}} //Define two-dimensional array writing method 3 irregular array class numfive{public static void main(String[] args){long[][] numfive=new long[5][]; //Define an irregular array of type long numfive[0]=new long[5]; //Assign 5 columns numfive[1]=new long[6]; //Assign 6 columns numfive[2]=new long[7]; //Assign 7 columns numfive[3]=new long[8]; //Assign 8 columns numfive[4]=new long[9]; //Assign 9 columns numfive[0][4]=100000000000L for row 5; //1 row 5 columns = 100000000000numfive[1][5]=200000000000L; //2 row 6 columns = 200000000000000numfive[2][6]=300000000000L; //3 row 7 columns = 30000000000000000000L = 3000000000000000L; //4 row 8 columns = 4000000000000000000L; //5 row 9 columns = 50000000000System.out.println(numfive[0][4]); //Print new line output System.out.println(numfive[1][5]);System.out.println(numfive[2][6]);System.out.println(numfive[3][7]);System.out.println(numfive[4][8]);System.out.println(numfive[4][7]); //Print output an array without array elements defined will automatically initialize it to 0}} //Define the 2-dimensional array writing method 4. Assign the initial value at the same time as the definition class numsix{public static void main(String[] args){double[][] numsix={{1.111D, 2.222D, 3.333D},{4.444D, 5.555D, 6.666D}};//Define the double-type array to allocate 3 rows and 3 columns spaces and assign the value System.out.println(numsix[0][0]); //Print the line break and output 1 row and 1 column = 1.111System.out.println(numsix[1][1]); //Print the line break and output 2 rows and 2 columns = 5.555}} //Define 2-dimensional array writing method 5 Define irregular 2-dimensional arrays and assign initial values class numseven{public static void main(String[] args){int[][] numseven=new int[][]{{10,20,30},{40,50},{60}}; //Nothing to say if you can't understand it, don't learn it! System.out.println(numseven[0][2]);System.out.println(numseven[1][1]);System.out.println(numseven[0][0]);}} //Define 2-dimensional array writing method 6 Define irregular 2-dimensional arrays and assign initial values at the same time; class numeight{public static void main(String[] args){int[][] numeight={{100,200,300,400},{500,600,700,800},{900,1000,1100,1200,1300}};System.out.println(numeight[0][2]);System.out.println(numeight[1][2]);System.out.println(numeight[2][1]);}}The above is the full content of several writing methods (summary) for Java definition two-dimensional arrays brought to you by the editor. I hope everyone will support Wulin.com~