1. Java's two-dimensional arrays are very widely used in practical applications. The following example shows the use of a two-dimensional array to print the maximum and minimum values in a set of data.
Public classmutiarray{intthevalues[][]={ {12,23,33,56,26}, {9,87,68,55,26}, {36,88,98,43,19}, {25,16,8,37,99} }; //a method for finding the smallest element in a two-dimensional array Public intminimum () {intLowthevalue=thevalues[0][0]; for(introw=0;row<thevalues.length;row++) { for(intcolumn=0;column<thevalues[row].length;column++) { if(Lowthevalue >Thevalues[row][column]) {Lowthevalue=Thevalues[row][column]; } } } returnLowthevalue; } //a method for finding the largest element in a two-dimensional array Public intmaximum () {intHighthevalue=thevalues[0][0]; for(introw=0;row<thevalues.length;row++) { for(intcolumn=0;column<thevalues[row].length;column++) { if(Highthevalue <Thevalues[row][column]) {Highthevalue=Thevalues[row][column]; } } } returnHighthevalue; } //Main Method Public Static voidMain (string[] args) {Mutiarray item=NewMutiarray (); System.out.println ("The smallest element in the array is:" +item.minimum ()); System.out.println ("The largest element in the array is:" +item.maximum ()); } }
2. Now look at the two-dimensional array that handles the same values in C #, as shown in the following code:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapparray{ Public classMutiarray { Public Static int[,] Mutiarray =New int[4,5]{ { A, at, -, About, -}, {9, the, the, -, -}, { $, the,98, +, +}, { -, -,8,Panax Notoginseng, About} }; //defining a two-dimensional array and initializing it//a method for finding the smallest element in a two-dimensional array Public Static intminimum () {intLowmutiarray = mutiarray[0,0]; for(introw=0; Row <mutiarray.getlength (0); row++) { for(intColumn =0; Column < Mutiarray.getlength (1); column++) { if(Lowmutiarray >mutiarray[row, column]) {Lowmutiarray=mutiarray[row, column]; } } } returnLowmutiarray; } //a method for finding the largest element in a two-dimensional array Public Static intmaximum () {intHighmutiarray = mutiarray[0,0]; for(introw =0; Row < Mutiarray.getlength (0); row++) { for(intColumn =0; column < Mutiarray.getlength (1); column++) { if(Highmutiarray <mutiarray[row, column]) {Highmutiarray=mutiarray[row, column]; } } } returnHighmutiarray; } } classProgram {Static voidMain (string[] args) { //traversing a two-dimensional array foreach(intIteminchMutiarray.mutiarray) {Console.Write (item+","); } Console.WriteLine (); Console.WriteLine ("The smallest element in a two-dimensional array is:"+mutiarray.minimum ()); Console.WriteLine ("The largest element in a two-dimensional array is:"+mutiarray.maximum ()); Console.ReadLine (); } }}
The execution results are as follows:
Java two-dimensional array and C # Two-dimensional data comparison