编写一个程序,将键盘从键盘读取到二维表中



我是社区的新手,我想知道我是否可以在这个程序上获得一些提示。除了为3x5表创建一个阵列并定义其他变量外,我不确定我应该如何继续这样做。我将非常感谢您的帮助

一个简短的脚本,用于从用户读取输入并填充表单元格,希望它可以让您开始并学习Java lang ...您应该很棒的

public static void main(String[] args) {
    int rows = 3;
    int cols = 5;
    int [][] table = new int[rows][cols];
    Scanner scanner = new Scanner(System.in);
    for (int i = 0 ; i < rows; i++){
        for (int j = 0 ; j < cols; j++){
            System.out.println("Enter value for cell[" + i + "][" + j + "]");
            int userInput = scanner.nextInt();
            table[i][j] = userInput;
        }
    }
}

注意:此示例没有任何输入检查和错误处理!

最新更新