从控制台输入一个整型数据n1,然后输入一个n1*n1的整型数组,接着输入一个整数n2,然后输入一个n2*n2的整型数组,接着输入整数n3……数组的数量未知,要求用两次回车结束输入,然后将所有输入的数组打印出来。
示例:
输入:
2
0 1
1 0
3
1 2 3
0 2 5
4 5 6输出:
0 1
1 0
1 2 3
0 2 5
4 5 6
下面是我的代码,问题出在输完第一个数组回车之后就不再能输入了,程序就往下运行了。
import java.util.Scanner;public class ForInput {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String s;
int[][] a = null;
while(!"".equals(s = in.nextLine())){
int n = Integer.parseInt(s);
a = new int[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
a[i][j] = in.nextInt();
}
}
}

for(int i=0; i<a.length; i++){
for(int j=0; j<a.length; j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}