1: Declaration and initialization (similar to initialization of one-dimensional arrays)
(1) data type array name []
(2) Array name =new array type [number of rows] [number of columns]
Multidimensional Arrays:
int [][][] ... []//array initialization is the same
2: Summation
1 Public classJavaerwei {2 3 Public Static voidMain (string[] args) {4//TODO auto-generated Method Stub5 inti,j,sum=0;6 intnum[][]={{ the, Wu, the, +},{ the, +, the, the}};7 for(i=0; i<num.length;i++) {//Line8System. out. println ("Section"+ (i+1)+"The personal results are:" );9 for(j=0; j<num[i].length;j++) {//ColumnTenSystem. out. Print (num[i][j]+" "); Onesum+=Num[i][j]; A } - } theSystem. out. println ("\ n the total."+sum+"points! "); - } -}
2: Change the value of the element
Array name [][]= array name [][]+ array name []
1 Public classUpdataarrays {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5 int[] arrays={{ One, A, -, -, the},{ +, A, at, -, -},{ to, +, -, the, *}};6arrays[0][0]=arrays[1][3]+arrays[2][0];7System. out. println (arrays[0][0]);8 }9 Ten}
3:for-each ()
For (type[] row: array name) {
for (type B:row)
Some operations on B Note: The variable names of the two row positions must be the same;
}
1 Public classErweiarray {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5 inta[][]=New int[5][4];6 for(intI=0; i<a.length;i++){7 for(intj=0; j<a[i].length;j++)8a[i][j]=i*J;9 }Ten for(int[] arr:a) { One for(intAbc:arr) { ASystem. out. Print (abc+"\ t");//\ t Table Form - } -System. out. println (); the } - } -}
4: Multidimensional (13-dimensional example)
public class Sanwei {public static void main (string[] args) {//TODO auto-generated method stub int i,j,k,sum=0; int a[][][]={{{5,1},{6,7}},{{9,4},{8,3}}}; for (i=0;i<a.length;i++) for ( j=0;j<a.length;j++) for ( k=0;k<a.length;k++) { System.out.print ("a[" +i+ "[" +j+ "] [" +k+ "]="); System.out.println (A[i][j][k]); SUM+=A[I][J][K]; } System.out.println ("sum=" +sum);}
Java. Two-dimensional and multidimensional