package hwtest.total;
import java.util.Random;
public class Array2DRandomReverse {
public static void main(String[] args) {
int[][] arr = {{4,3,32,5},{1,2,3,4},{9,6,5,4}};
for(int i = 0;i<arr.length;i++) {
for(int j = 0;j<arr[i].length;j++) {
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println();
int[][] arr2 = arrRandomReverse(arr);
for(int i = 0;i<arr2.length;i++) {
for(int j = 0;j<arr2[i].length;j++) {
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
}
public static int[][] arrRandomReverse(int[][] arr) {
int[][] resArr = new int[arr.length][];
for(int i = 0 ;i<arr.length;i++) {
resArr[arr.length-1-i] = arr[i];
}
Random r = new Random();
for(int i = 0 ;i<resArr.length;i++) {
for(int j = 0;j<resArr[i].length;j++) {
int p = r.nextInt(resArr[i].length);
int tmp;
tmp = resArr[i][j];
resArr[i][j] = resArr[i][p];
resArr[i][p] = tmp;
}
}
return resArr;
}
}
import java.util.Random;
public class Array2DRandomReverse {
public static void main(String[] args) {
int[][] arr = {{4,3,32,5},{1,2,3,4},{9,6,5,4}};
for(int i = 0;i<arr.length;i++) {
for(int j = 0;j<arr[i].length;j++) {
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println();
int[][] arr2 = arrRandomReverse(arr);
for(int i = 0;i<arr2.length;i++) {
for(int j = 0;j<arr2[i].length;j++) {
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
}
public static int[][] arrRandomReverse(int[][] arr) {
int[][] resArr = new int[arr.length][];
for(int i = 0 ;i<arr.length;i++) {
resArr[arr.length-1-i] = arr[i];
}
Random r = new Random();
for(int i = 0 ;i<resArr.length;i++) {
for(int j = 0;j<resArr[i].length;j++) {
int p = r.nextInt(resArr[i].length);
int tmp;
tmp = resArr[i][j];
resArr[i][j] = resArr[i][p];
resArr[i][p] = tmp;
}
}
return resArr;
}
}