国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

新手求大神,有其他swit-case的思路寫這個程序么?

2019-11-17 03:18:40
字體:
來源:轉載
供稿:網友

新手求大神,有其他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();        }    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙井市| 浮梁县| 额尔古纳市| 仪陇县| 巧家县| 晋宁县| 西畴县| 油尖旺区| 佳木斯市| 铜山县| 宿迁市| 瑞安市| 会宁县| 高阳县| 凤庆县| 顺义区| 抚松县| 沿河| 儋州市| 佳木斯市| 陆丰市| 金塔县| 崇义县| 韩城市| 沧州市| 台前县| 香格里拉县| 九江县| 常山县| 南皮县| 陇西县| 三亚市| 铜陵市| 临朐县| 芜湖市| 板桥市| 颍上县| 临夏市| 甘孜| 镶黄旗| 平远县|