有人可以帮我弄清楚写这个while循环吗?

问题描述

我真的很努力地了解如何根据说明编写while循环。有人可以告诉我该怎么做吗?我已经尝试在下面编写自己的代码,这很糟糕。

以下是说明:

编写一个由哨兵控制的while循环,使您可以计算任何月份的平均低温。平均温度应显示为正确计算的两倍值。解释为什么选择了哨兵值。提供了用于输入初始温度值的代码

这是我的代码

Scanner scan = new Scanner(system.in);
int temp = scan.nextInt();

while ()
{
    temp = 5.0/9.0 * (temp - 32.0);
    System.out.println()
}

解决方法

前哨是任何非数字字符串:

tf.contrib

您的原始代码也试图将华氏温度转换为摄氏温度,即使问题说明中没有提及磅秤。

,
int n = scan.nextInt();           //to input number of days in a given month
int[] temp = new int[n];          //an array to store the low temps of all days
int i=0,total=0;
double avg=0.0;
while (i<n)
{   
    temp[i] = scan.nextInt();     //input temperature per day one at a time
    total=total+temp[i];          //to get the sum total of all days of the month
    i++                           //increment the counter i
}
avg=total/n;
System.out.println("the average low temperature is :"+avg);```