有沒(méi)有更簡(jiǎn)便的寫(xiě)法
public class HelloWorld{
? ? public static void main(String[] args) {
double score=80;
boolean a=score>=60;
boolean b=score<70;
boolean c=score>=70;
boolean d=score<80;
boolean e=score>=80;
boolean f=score<60;
String mark=((f==true)?"不合格":"");
String mark1=((a&&b==true)?"合格":"");
String mark2=(c&&d==true)?"良好":"";
String mark3=(e==true)?"優(yōu)秀":"";
System.out.println("成績(jī)"+mark+mark1+mark2+mark3);
}
}
2017-03-11
先判斷在哪個(gè)分?jǐn)?shù)段,再用switch輸出。
或者使用三元表達(dá)式嵌套(其實(shí)就是if語(yǔ)句的嵌套),不過(guò)這樣可讀性會(huì)很差