日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

新手求大神,有其他swit-case的思路写这个程序么?

發布時間:2023/12/13 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 新手求大神,有其他swit-case的思路写这个程序么? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

兩個程序:

switch-case與if-else if的區別
相同點:可以實現多分支結構;
不同點:
switch:一般只能用于等值比較.(可以進行范圍運算???---學會用switch計算范圍出爐的思路____待解決)
if_else if:可以處理范圍計算.

?

switch(變量)

{

case 變量:

break;

}?

switch括號中的"變量"與case表達式中的"變量" 必須是同一類型,
或者是相兼容的數據類型.(一般是int類型或者string類型?).

?

using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace 練習2 {class Program{static void Main(string[] args){//對成績進行考核評級Console.WriteLine("請輸入你的成績?");int score = Convert.ToInt32(Console.ReadLine()); switch (score/10){case 10:Console.WriteLine("A");break;case 9:Console.WriteLine("A");break;case 8:Console.WriteLine("B");break;case 7:Console.WriteLine("C");break;case 6:Console.WriteLine("D");break;default:Console.WriteLine("E");break;}Console.ReadKey();}} }

總感覺這種方法有點繞思維,有可以直接判斷的么?難道只能用if-else if來寫么??? ↓↓↓

using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace if_else_if寫switch作業 {class Program{static void Main(string[] args){Console.WriteLine("請輸入你的成績?");int score = Convert.ToInt32(Console.ReadLine());if (score >= 90){Console.WriteLine("A");}else if (score >= 80){Console.WriteLine("B");}else if (score >= 70){Console.WriteLine("C");}else if (score >= 60){Console.WriteLine("D");}else {Console.WriteLine("E");}Console.ReadKey();}} }

?

轉載于:https://www.cnblogs.com/jerryho/p/3592808.html

總結

以上是生活随笔為你收集整理的新手求大神,有其他swit-case的思路写这个程序么?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。