解题思路:
先编写矩阵,然后进行转置
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();//行数
int m = scanner.nextInt();//列数
int[][]B = new int[m][n];
//A矩阵
int[][]A = new int[n][m];
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++){
A[i][j] = scanner.nextInt();
}
}
//B矩阵
for (int i = 0; i < m; i ++){
for (int j = 0; j < n; j ++){
B[i][j] += A[j][i];
}
}
//输出B矩阵
for (int i = 0; i < m; i ++){
for (int j = 0; j < n; j ++){
System.out.print(B[i][j] + " ");
}
System.out.println();
}
}
}
0.0分
0 人评分