這樣跟if else 比哪個(gè)好一點(diǎn)?
public class HelloWorld {
? ? public static void main(String[] args) {
int age=25;
String x = (age>70) ? "老年":((age>=40&&age<=60)?"中年":(age>=18&&age<=40)?"青年":"童年") ;
System.out.println(x);
}
}
public class HelloWorld {
? ? public static void main(String[] args) {
int age=25;
String x = (age>70) ? "老年":((age>=40&&age<=60)?"中年":(age>=18&&age<=40)?"青年":"童年") ;
System.out.println(x);
}
}
2022-07-15
舉報(bào)
2022-08-26
if else的條理會更清晰些? ?當(dāng)遇到更多情況的時(shí)候if else的優(yōu)勢就體現(xiàn)出了