Java two-dimensional array and C # Two-dimensional data comparison

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.