0
我有這個程序,它使用用戶輸入來查找輸入的數字的總和,以及用戶輸入的最小數字和多少個整數。關於哨兵的問題?初學Java編程
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
_
,它不允許從用戶輸入了。爲什麼程序不會繼續?