问题描述
**下面的程序使用for循环将2个数组的值存储在一个二维数组a [] []和一个数组“ a []”中。在运行时,它只接受一次输入,而跳过输入随后的运行,并且没有用户输入,但它输出语句**
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();
}
}
解决方法
在读取int之后消费下一行
for(int j=0;j<5;j++)
{
a[i][j]=obj.nextInt();
}