我根据摄氏温度和海拔高度编写代码来确定水的状态,如何在最后完成,如果海拔高于300,则需要1摄氏度以下的摄氏温度。煮沸的水和结果可以根据输入确定?
import java.util.Scanner;
public class WaterState
{
public static void main(String[] args)
{
boolean run = true;
while(run)
{
Scanner scan = new Scanner(System.in);
System.out.println("What is the temperature in degrees Celsius?");
double temp = scan.nextDouble();
System.out.println("What is the height above Sea level? in exact meters");
double altitude = scan.nextDouble();
int freezingPoint = 0;
double alternateAltitude = temp - (altitude * 0.001);
double boilingPoint = 100;
int baseAltitude = 300;
if ((temp <= freezingPoint) && (altitude <= baseAltitude))
{
System.out.println("Water is frozen");
}
else if ((temp > freezingPoint) && (altitude <= baseAltitude))
{
System.out.println("Water is liquid");
}
else if ((temp >= boilingPoint) && (altitude <= baseAltitude))
{
System.out.println("Water is gaseus");
}
else if ((altitudeChange > )
{
System.out.println("Water is boiling, but at a lower temperature because of the altitude");
}
}
}
}
答案 0 :(得分:0)
以下是您的问题的相关内容:
else if ((altitudeChange > ){
System.out.println("Water is boiling, but at a lower temperature because of the altitude");
}
根据你的意见:
如果海拔高于300,则需要1摄氏度 水煮沸,结果可以根据 输入
这是你想要的:
if(altitude >=baseAltitude && temp>(boilingPoint -(altitude/baseAltitude *1)) ){//1.altitude is more than 300,2.temp is higher than the new degree celsius to boil
System.out.println("Water is boiling, but at a lower temperature because of the altitude");
}