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