我有这个程序使用用户输入来查找输入的数字的总和,以及用户输入的最小数字和整数。
public static void main(String args[])
{
int numOfints = 0;
int numberin;
int sum = 0;
int small;
Scanner input = new Scanner(System.in);
System.out.print("Please enter the numbers. <-999 to stop>: ");
System.out.print("Please enter the first number: ");
numberin = input.nextInt();
small = numberin;
while(numberin!=-999)
{
numOfints++;
sum+=numberin;
}
if (numberin >0)
{
System.out.println("Total number of numbers inputted was" +numOfints);
System.out.println("The sum of these numbers is " + sum);
System.out.println("The smallest number in the set is" + small);
}
else
System.out.println("The number set is empty, therefore no calculations can be performed.");
}
}
{
然而,当我运行程序时,唯一出现的是
c:\jwork>java lab7a
Please enter the numbers; <-999 to stop>: Please enter the first number: 1
_
并且它不允许来自用户的任何输入。为什么程序不会继续?
答案 0 :(得分:1)
您没有任何方法可以在while
循环中获取用户的输入。