JAVA, finding the maximum value of 2*2 order matrix in M*n order matrix

Source: Internet
Author: User

Title: Enter a m*n order matrix to find the maximum value of the second order matrix in the M*n matrix

Input Sample:

1 2 3 0 4;4 3 5 1 2;3 2 4 7 5

Sample output:

17

------------------------------------------------I am a dividing line---------------------------------------------

Java code:

Import java.util.scanner;/** * 2*2-order matrix and maximum value in M*n-order matrix *  * @author foreverlover * */public class Matrix {public static void Main (string[] args) {Scanner scan = new Scanner (system.in); int m;int n; String s = scan.nextline (); string[] sa = S.split (";"); m = sa.length; string[][] ss = new String[m][];for (int i = 0; i < m; i++) ss[i] = Sa[i].split (""); n = ss[0].length;int[][] array = NE W int[m][n];for (int i = 0; i < m; i++) {for (int j = 0; J < N; j + +) {Array[i][j] = Integer.parseint ((ss[i][j));}} int max = 0;for (int i = 0; i < m-1; i++) {int sum = 0;for (int j = 0; J < N-1; J + +) {sum = Array[i][j] + array[ I][j + 1] + array[i + 1][j]+ array[i + 1][j + 1];max = Sum >= max? Sum:max;}} SYSTEM.OUT.PRINTLN (max);}}

  

JAVA, finding the maximum value of 2*2 order matrix in M*n order matrix

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.