سؤال

I have this program that uses user input to find sum of number entered, aswell as the smallest numbers and how many integers have been entered by the users.

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.");

}

}

{

However when I run the program the only thing that appears is

c:\jwork>java lab7a
Please enter the numbers; <-999 to stop>: Please enter the first number: 1
_

and it does not allow for anymore inputs from the user. Why won't the program continue?

هل كانت مفيدة؟

المحلول

You don't have any methods of getting input from the user within your while loop.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top