国产探花免费观看_亚洲丰满少妇自慰呻吟_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();        }    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿拉善左旗| 莱西市| 得荣县| 辽宁省| 琼海市| 安新县| 喀喇| 华容县| 石家庄市| 西平县| 荥阳市| 绵竹市| 兰州市| 华阴市| 梓潼县| 黄浦区| 万荣县| 万安县| 承德县| 简阳市| 满洲里市| 新和县| 阳城县| 乌兰浩特市| 广德县| 怀安县| 柳江县| 开封县| 合作市| 蓬溪县| 济阳县| 西林县| 克东县| 甘洛县| 健康| 辽宁省| 太保市| 新晃| 平昌县| 浦城县| 汉阴县|