二维数组,每一维想要输入任意个数的字符用空格隔开时可以用以下代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int a[][]=new int[100][100];
int n;
Scanner in=new Scanner(System.in);
n=in.nextInt();
//跳过这行换行符
in.nextLine();
for(int i=0;i<n;i++){
String strLine = in.nextLine();
Scanner s = new Scanner(strLine);
int j=0;
while(s.hasNextInt()){
a[i][j++]=s.nextInt();
}
}
//输出
for( int i=0;i<n;i++){
int j=0;
while(a[i][j]!=0)
System.out.print(a[i][j++]+" ");
System.out.println();
}
}
}