(编写if-else if语句(不是完整的程序,只是if-else语句),将“temp”变量与面的值进行比较,并根据条件输出下面的语句。)
temp>=50:"Take underground shelter and call for help"
temp>=40:"Stay Indoor and avoid hot activities"
temp>=30: “Drink lot of water "
if(temp>=50){
System.out.println("Take underground shelter and call for help");
}else if (temp>=40){
System.out.println("Stay Indoor and avoid hot activities");
}elseif (temp>=30){
System.out.println("Drink lot of water");
}
if(temp>=50) {
System.out.println("Take underground shelter and call for help");
}else if(temp>=40) {
System.out.println("Stay Indoor and avoid hot activities");
}else if(temp>=30) {
System.out.println("Drink lot of water");
}
if(temp >= 50) {
System.out.println("Take underground shelter and call for help");
} else if(temp >= 40) {
System.out.println("Stay Indoor and avoid hot activities");
} else if(temp >= 30) {
System.out.print("Drink lot of water");
}
if(temp >= 30 && temp < 40){
System.out.println("Take underground shelter and call for help");
}else if(temp >= 40 && temp < 50){
System.out.println("Stay Indoor and avoid hot activities");
}else if(temp >= 50){
System.out.println("Take underground shelter and call for help");
}else{
System.out.println("invalid num");
}
有帮助的话请采纳~~
可以从输入获取一个int值赋值给temp变量,也可以直接给它赋值,然后使用if-else语句来根据不同的条件打印不同的语句即可,一个实现如下:
import java.util.Scanner;
public class TempTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int temp = sc.nextInt();// 获取一个int值,赋值给temp
// 根据temp的不同值,打印不同的提示语句
if(temp>=50) {
System.out.println("Take underground shelter and call for help");
}else if(temp>=40) {
System.out.println("Stay Indoor and avoid hot activities");
}else if(temp>=30) {
System.out.println("Drink lot of water");
}
}
}