import java.util.Scanner;
public class TwoDimensionalArray {
public static void TwoDimensionalArray_M(){
Scanner input = new Scanner(System.in);
String[][] newString = new String[3][2];
for (int i = 0; i < newString.length; i++) {
for (int j = 0; j < newString[i].length; j++) {
System.out.println(i +" "+ j);
if ( i == j || j>=i) {
System.out.println("First Name:");
}else {
System.out.println("Last Name:");
}
newString[i][j] = input.nextLine();
}
}
System.out.println("All Value are inputed");
}
}
答案 0 :(得分:0)
从我可以收集到的内容,您希望此2D数组的第一个维度引用特定的人,并且此2D数组的第二个维度引用特定人员的特定名称(第一个或最后一个,具体取决于索引)。
import java.util.Scanner;
public class TwoDimensionalArray {
public static void TwoDimensionalArray_M(){
Scanner input = new Scanner(System.in);
int numNames=3;
String[][] newString = new String[numNames][2];
for (int i=0; i<newString[numLastNames].Length; i++)
{
System.out.println("Input first name for index " + i + ":");
newString[i][0] = input.nextLine();
System.out.println("Input last name for index " + i + ":");
newString[i][1] = input.nextLine();
}
System.out.println("All values have been inputted.");
}
}