微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决有人可以帮我弄清楚写这个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);```

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。