//以下是我写的代码,虽然有点儿多,给高手看了可能还惹笑话,但好歹也花了我一个多小时琢磨,希望LZ给分 (本人测试后有效)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Teacher1 {
//从控制台输入一个M*N矩阵,输出行列互换后的矩阵
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入M...");
int m = sc.nextInt();
System.out.println("请输入M...");
int n = sc.nextInt();
System.out.println("你输入的M和N分别为:"+m+" , "+n);
boolean allow = false;
do{
allow = false;
System.out.println("现在您需要连续输入 "+m*n+"个整数,并以逗号隔开\n");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
String [] s = line.trim().split(",");
if(s.length != m*n){
System.out.println("输入长度有误,请重输!");
allow = true;
}else{
String [][] str2s = new String[m][n];
int count = 0;
for(int i=0;i
}
}
System.out.println("----数组原样----");
print2Array(str2s, m, n);
System.out.println("----替换结果----");
replace2Array(str2s, m, n);
}
}while(allow);
}
private static void print2Array(String[][] str2s,int m, int n){
for(int i=0;i
}
System.out.print("\n");
}
}
private static void replace2Array(String[][] str2s, int m, int n){
String line[] = new String[m*n];
int count = 0;
for(int i=0;i
}
}
count = 0;
String[][] strR2s = new String[n][m];
for(int i=0;i
}
}
print2Array(strR2s, n ,m);
}
}
撸过 代码自己写 不要复制
稍等一会发给你