132-使用if else if else語句進行多條件判斷
阿新 • • 發佈:2018-11-16
分支-if語句的其他結構
if (){
}else if(){
}else if(){
}else{
}
else if可以有0或者多個
else 只能有0或者1個
編寫一段程式,執行時候向用戶提問“你考了多少分?(0-100)” ,接受輸入後判斷其等級並顯示出來。等級判斷標準如下:
等級={優{90-100}; 良 {80-89}; 中{60-79}; 差{0-59}}
Console.WriteLine("您考了多少分?"); string str = Console.ReadLine(); int score = Convert.ToInt32(str); if (score >= 90) { Console.WriteLine("優秀"); }else if (score >= 80 && score <= 89) { Console.WriteLine("良"); }else if (score >= 60 && score <= 79) { Console.WriteLine("中"); } else { Console.WriteLine("差,繼續努力哦!"); } Console.ReadKey();