繁体   English   中英

对哨兵有疑问吗? 初学者Java编程

[英]Questions about sentinels? Beginner Java Programming

我有这个程序,它使用用户输入来查找输入数字的总和,以及最小的数字和用户输入的整数个数。

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
_

并且它不再允许用户输入。 为什么程序不继续?

while循环中,您没有任何从用户那里获取输入的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM