嘿伙计们,我正在制作一个数字平均程序,我想插入这个函数,允许用户输入字母“y”再次运行并进行另一次计算,但是,我的程序显示了终止的消息(我正在使用Eclipse)在第一次计算之后,即使我希望用户能够输入输入。以下是令我困惑的源代码部分:
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
System.out.print("This is an averaging program. How many numbers would you like to average together?");
int total=input.nextInt();
int i;
float sum=0;
for(i=0; i<total; i++)
{
System.out.print("Enter your numbers: ");
sum += input.nextFloat();
}
String y;
System.out.print("Your average is: " + sum/total + "\n");
System.out.print("Would you like to do another computation? Type y for yes, or something else for no.");
y=input.nextLine();