我正在编写一个程序,您将在其中使用扫描仪输入温度。您可以输入任意数量的温度,当您输入 -100 时,程序将停止,然后为您提供最低、最高、平均和总注册温度。我已经取得了一些成功,但无法弄清楚如何获得最小值、总数和平均工作量。现在被困在这里一段时间了。
import java.util.Scanner;
public class Tempratureprograme {
public static void main(String[] args) {
temperatures();
}
public static void temperatures(){
double temperature;
double biggest = 0;
double smallest = 0;
double totalNum = 0;
double counter = 1;
int numberAmount = 0;
double average = totalNum/numberAmount;
Scanner input = new Scanner(System.in);
System.out.println("Please enter the temperature(s) - end the program with -100");
System.out.print("-> ");
do {
temperature = input.nextDouble();
numberAmount++;
totalNum = totalNum + temperatur;
System.out.print("-> ");
if(temperature > max)
{
max=temperature;
counter= 0;
}
if(temperature < min)
{
min = temperature;
}
}
while (temperature != -100);
System.out.println();
System.out.println("Highest temperature: " + max);
System.out.println("Lowest temperature: " + min);
System.out.println("Average temprature: " + average);
System.out.println("Total registered tempratures: " + totalNum);
}
}