格式:
xx xx
xx xx
xx xx
public static void main(String[] args) {
String[][] a=new String[3][2];
Scanner input=new Scanner(System.in);
System.out.println("输入人名");
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
a[i][j]=input.nextLine();
}
}
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
String[][] a=new String[3][2];
Scanner input=new Scanner(System.in);
System.out.println("输入人名");
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
a[i][j]=input.nextLine();
}
}
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-04-09
public static void main(String[] args) {
String[][] names = new String[3][2];
for (int i = 0; i < 3; i++) {
String[] temp = new String[2];
for (int j = 0; j < temp.length; j++) {
temp[j] = "name"+i+j;
}
names[i] = temp;
}
for (int i = 0; i < names.length; i++) {
String[] temp = names[i];
for (int j = 0; j < temp.length; j++) {
System.out.print(temp[j] + "\t");
}
System.out.println();
}
}
String[][] names = new String[3][2];
for (int i = 0; i < 3; i++) {
String[] temp = new String[2];
for (int j = 0; j < temp.length; j++) {
temp[j] = "name"+i+j;
}
names[i] = temp;
}
for (int i = 0; i < names.length; i++) {
String[] temp = names[i];
for (int j = 0; j < temp.length; j++) {
System.out.print(temp[j] + "\t");
}
System.out.println();
}
}