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