【问题标题】:The loop takes input once and for the second and consecutive runs it skips the inputs but print the statements given循环接受一次输入,对于第二次和连续运行,它会跳过输入但打印给定的语句
【发布时间】:2020-09-07 09:27:33
【问题描述】:

**以下程序使用 for 循环将值存储在二维数组 a[][] 和数组“a[]”中,用于 5 个输入。运行时它只接受一次输入并跳过以下运行并且不接受用户输入,但它会打印语句**

    for(int i=0;i<5;i++) 
    {
        System.out.println("Enter the name  of Salesman = ");
        name[i]=obj.nextLine();
        System.out.println("Enter the product quantity for " +name[i]);
        for(int j=0;j<5;j++)
        {
            a[i][j]=obj.nextInt();
        }
    }

【问题讨论】:

标签: java arrays loops printing java.util.scanner


【解决方案1】:

读取一个 int 后使用下一行

for(int j=0;j<5;j++)
    {
        a[i][j]=obj.nextInt();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 2018-09-18
    • 2019-08-11
    • 2020-05-28
    • 2021-08-26
    • 2021-12-30
    相关资源
    最近更新 更多