Big Data-java Foundation -4day

Source: Internet
Author: User

4th Day

-------------------------

Transpose of the array:

1, the precondition is that the two-dimensional array is a square, that is, n rows n columns.

/**

* Transpose of two-dimensional data

*/

public class Arraytransdemo {


public static void Main (String [] args) {

String[][] arr = {{"A", "B", "C", "D", "E"},{"F", "G", "H", "I", "J"},{"K", "L", "M", "N", "O"},{"P", "Q", "R", "s", "T"},{"U", "V" "," W "," X "," Y "}};

Print (arr);

SYSTEM.OUT.PRINTLN ("------------------------------after transpose");

Trans (arr);

Print (arr);

}

private static string [] trans (string [] arr) {

for (int i = 0; i < arr.length; i++) {

for (int j = 0; J < Arr[i].length; J + +) {

if (J > i) {

String temp = "";

temp = Arr[i][j];

ARR[I][J] = Arr[j][i];

Arr[j][i] = temp;

}

}

}

return arr;

}

private static void Print (String [] arr) {

for (int i = 0; i < arr.length; i++) {

for (int j = 0; J < Arr[i].length; J + +) {

System.out.print (Arr[i][j] + "\ t");

}

System.out.println ();

}

}

}


/**

* Three-dimensional array printing

*/

public class Array3printdemo {


public static void Main (string[] args) {

int [][][] arr = {{{1,2,3},{4,5,6},{7,8,9}},{{10,11,12},{13,14,15},{16,17,18}},{{19,20,21},{22,23,24},{25,26,27}}} ;

Print (arr);

}


private static void print (int [][][] arr) {

for (int i = 0; i < arr.length; i++) {

for (int j = 0; J < Arr.length; J + +) {

for (int k = 0; k < arr.length; k++) {

System.out.print (Arr[j][i][k] + "\ t");

}

System.out.print ("|\t");

}

System.out.println ();

}

}

}


Big Data-java Foundation -4day

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.