"Java Experiment three"

Source: Internet
Author: User

//to find the largest number in an array:ImportJava.util.Scanner;classmax{ Public Static voidMax (intS[][],intMintN) {intmax = S[0][0]; intT;        System.out.println ();  for(m=0;m<3;m++)        {             for(n=0;n<5;n++)            {                if(s[m][n]>max) {Max=S[m][n]; }}} System.out.println ("The largest element in the array is:");    SYSTEM.OUT.PRINTLN (max); }     Public Static voidMain (string[] args) {inti; intj = 0; int[] A =New int[3] [5]; Scanner in=NewScanner (system.in); System.out.println ("Please enter an array of 3 rows and 5 columns:");  for(i=0;i<3;i++)        {             for(j=0;j<5;j++) {A[i][j]=In.nextint ();    }} Max (A,I,J); }}
//to find the diagonal elements of the N-order matrix:ImportJava.util.Scanner;classsum{ Public Static voidSumintC[][],intm) {intI,s = 0;  for(i=0;i<m;i++) s= S+c[i][i]+c[i][m-i-1]; if(m%2==0) System.out.println ("The sum of the diagonal elements is:" +s); Else{s= S-C[M/2][M/2]; System.out.println ("The sum of the diagonal elements is:" +s); }    }     Public Static voidMain (string[] args) {inti,j; Scanner in=NewScanner (system.in); System.out.println ("Please enter the order of the N-Order matrix:"); intn =In.nextint (); intB[][] =New int[N][n]; System.out.println ("Please enter an n-row N-column array:");  for(i=0;i<n;i++)        {             for(j=0;j<n;j++) {B[i][j]=In.nextint ();    }} sum (B,n); }}

"Java Experiment three"

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.