這樣正確嗎
public class HelloWorld{
? ? public static void main(String[] args) {
int score=68;
String mark =(score>=60)?"及格":"不及格";
System.out.println("考試成績如何:"+mark);
}
}
public class HelloWorld{
? ? public static void main(String[] args) {
int score=68;
String mark =(score>=60)?"及格":"不及格";
System.out.println("考試成績如何:"+mark);
}
}
2016-01-30
舉報
2016-01-30
這個題只有兩種可能的結果,用if要簡單得多
public class HelloWorld{
? ? public static void main(String[] args) {
? ? ? ? int score = 68;
? ? ? ? if(score>=60){
? ? ? ?System.out.println("考試成績如何: 及格!");
? ? ? ? ? ? ? }else{
System.out.println("考試成績如何:不及格!");
? ? ? ?}
}
2016-01-30
你的?和這句的;好像是用中文打的,因此程序會報錯,這樣做事沒錯的,只要把格式改過來就行
2016-01-30
這樣是對的,沒有問題。
2016-01-30
用if判斷語句來判斷更不容易出錯。我也不知道這樣可不可以,你可以運行一下試一試。