Java:多维数组

Java:多维数组,java,multidimensional-array,Java,Multidimensional Array,我正在做多维数组,它将打印一个数组,其中至少有2个姓名,并在用户输入后显示相应的年龄和薪水。但当我运行程序时,它会给我空内容。下面是我的代码。非常感谢你的帮助 import java.util.Scanner; public class Employee { public static void main(String [] args) { Scanner input = new Scanner(System.in); String employee

我正在做多维数组,它将打印一个数组,其中至少有2个姓名,并在用户输入后显示相应的年龄和薪水。但当我运行程序时,它会给我空内容。下面是我的代码。非常感谢你的帮助

import java.util.Scanner;

public class Employee {
    public static void main(String [] args) {

        Scanner input = new Scanner(System.in);

        String employeeList [][] = new String [2][3];

        // populating
        for (int i=0; i<employeeList.length; i++){
            System.out.println("Employee #" + (i+1));
            for (int j=0; j<employeeList[i].length; j++){
                System.out.print("Name\t:");
                employeeList [i][j] = input.nextLine();             
                System.out.print("Age\t:");
                employeeList [i][j]= input.nextLine();
                System.out.print("Salary\t:");
                employeeList [i][j]= input.nextLine();
                break;  
            }           
        }

        //System.out.println();
        //System.out.println();

        //displaying
        System.out.printf("%15s%15s%15s\n", "NAME", "AGE", "SALARY");
        for (int i=0; i<employeeList.length; i++){
            for (int j=0; j<employeeList[i].length; j++){
                System.out.printf("%15s", employeeList[i][j]);
            }
            System.out.println();
        }
    }
}
import java.util.Scanner;
公营雇员{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
字符串employeeList[][]=新字符串[2][3];
//填充

对于(int i=0;i内部循环没有意义,因为您将姓名、年龄和薪资存储在第一列(
employeeList[i][0]
),这意味着薪资将覆盖其余输入

您希望将每个输入存储在数组当前行的不同列中

只需使用一个循环:

for (int i=0; i<employeeList.length; i++){
        System.out.println("Employee #" + (i+1));
        System.out.print("Name\t:");
        employeeList [i][0] = input.nextLine();             
        System.out.print("Age\t:");
        employeeList [i][1] = input.nextLine();
        System.out.print("Salary\t:");
        employeeList [i][2] = input.nextLine();
}

for(int i=0;i为什么代码包含一个
中断