程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#基礎知識 >> choosesubject c# switch

choosesubject c# switch

編輯:C#基礎知識
代碼如下:

using System;
class ChooseSubject
{
    static void Main()
    {
        int i;
        string str;
        Console.WriteLine ("Please choose your favorite subjects:-1 is quit.");
        Console.WriteLine ("1.Chinese.");
        Console.WriteLine ("2.Maths.");
        Console.WriteLine ("3.English.");
        Console.WriteLine ("4.Physical.");
        Console.WriteLine ("-1 is quit.");
        do
        {
            str=Console.ReadLine ();
            i=Int32.Parse (str);
            switch(i)
            {
                case 1:
                    Console.WriteLine ("You like chinese very much.");
                    break;
                case 2:
                    Console.WriteLine ("You like maths very much.");
                    break;
                case 3:
                    Console.WriteLine ("You like english very much.");
                    break;
                case 4:
                    Console.WriteLine ("You like physical very much.");
                    break;
                case -1:
                    break;
                default:
                    Console.WriteLine ("I'm sorry.You can't choose this subject.");
                    break;
            }

        }while(i!=-1);
        Console.WriteLine ("Byebye!");
    }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved