```java
public class MatrixTranspose {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[][] transposedMatrix = transpose(matrix);
for (int i = 0; i < transposedMatrix.length; i++) {
for (int j = 0; j < transposedMatrix[i].length; j++) {
System.out.print(transposedMatrix[i][j] + " ");
}
System.out.println();
}
}
public static int[][] transpose(int[][] matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
int[][] transposedMatrix = new int[cols][rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transposedMatrix[j][i] = matrix[i][j];
}
}
return transposedMatrix;
}
}
```
public class MatrixTranspose {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[][] transposedMatrix = transpose(matrix);
for (int i = 0; i < transposedMatrix.length; i++) {
for (int j = 0; j < transposedMatrix[i].length; j++) {
System.out.print(transposedMatrix[i][j] + " ");
}
System.out.println();
}
}
public static int[][] transpose(int[][] matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
int[][] transposedMatrix = new int[cols][rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transposedMatrix[j][i] = matrix[i][j];
}
}
return transposedMatrix;
}
}
```