Reconciliation of elements in two Arrays

Source: Internet
Author: User

[Java]
/* (Start of program header annotation) </p> <p> * copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* Author: Li Zhaoqing
* Completion date: January 1, September 17, 2012
* Input description:
* Problem description and output: compile a Java application,
* Function: You can call the element with the largest median value in a two-dimensional array to the element in the upper left corner. Then, you can call the element with the smallest value to the element in the lower right corner. For example:
1 4 5 6
7 2 10 11
9 8 12 3,
Reconciliation result
12 4 5 6
7 2 10 11
9 8 3 1
* End the comment in the program Header
*/
 
Public class Num {
 
/**
* @ Param args
*/
Public static void main (String [] args ){

Int [] [] a = {1, 4, 5, 6}, {7, 2, 10, 11}, {8, 9, 12, 3 }};

System. out. println ("pre-tuning output array :");

PrintMatrix (a); // outputs an array in two-dimensional mode

System. out. println ("the output array after callback is :");

PrintNewMatrix (a); // The output array after reconciliation
 
}

// Outputs an array in two-dimensional mode

Static void printMatrix (int [] [] ){

For (int I = 0; I <3; I ++ ){

For (int j = 0; j <4; j ++ ){

System. out. print (a [I] [j] + "");

}

System. out. println ();
}

}

// Output array after reconciliation

Static void printNewMatrix (int [] [] ){

Int t, x;

T = a [2] [3];

A [2] [3] = a [2] [2];

A [2] [2] = t;

X = a [0] [0];

A [0] [0] = a [2] [3];

A [2] [3] = x;

For (int I = 0; I <3; I ++ ){

For (int j = 0; j <4; j ++ ){

System. out. print (a [I] [j] + "");

}

System. out. println ();
}

}
 
}

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.