java For 循环将值输入到二维数组中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13131763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:36:36  来源:igfitidea点击:

For loop to input values into a 2d array

javajava.util.scanner

提问by peter_gent

Scanner input = new Scanner(System.in);

System.out.println("Enter matrix 1: ");
for(int row=0;row<3;row++){
    for(int col=0;col<3;col++){
        a[row][col]=input.nextDouble();
    }
}

Hi there - Given the above solution to entry of data into a 2d 3*3 array called a, I'm currently unable to take user input. The intellij ide won't accept any input that I can see at the point of input.nextDouble().

您好 - 鉴于上述将数据输入到名为 的 2d 3*3 数组的解决方案a,我目前无法接受用户输入。intellij ide 不会接受我在input.nextDouble().

I guess I'm missing something obvious but what ? :)

我想我错过了一些明显的东西,但是什么?:)

回答by PermGenError

The below code works perfectly for me

下面的代码非常适合我

double a[][]=new double[3][3];
        Scanner input = new Scanner(System.in);

        for(int row=0;row<3;row++){

            for(int col=0;col<3;col++){
                System.out.println("Enter value: ");
                a[row][col]=input.nextDouble();
            }
        }

回答by peter_gent

It's JUNIT4 not taking console input - that's why changing focus to the console produces no result.

这是 JUNIT4 不接受控制台输入 - 这就是将焦点更改为控制台不会产生任何结果的原因。