码迷,mamicode.com
首页 > 其他好文 > 详细

语句(switch case)

时间:2014-10-14 16:19:58      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:os   ar   for   strong   sp   数据   2014   on   ad   

 /* C#:语句     判断,循环,形成循环的分支和循环                

选择控制:if    else,     switch    case                

选择控制:while,do,for.foreach                

跳转语句:break,continue                

异常处理:try,catch,finally             

*/            /* int casezhi = 1;            

switch (casezhi)    //小括号内是一个数据类型的值           

  {                 //case 后面加空格,之后写上跟小括号内对应类型的 可能出现的值              

   case 1:                    

   Console.Write("");                  

   break;         //跳转语句。  跳出 包含break 最近的{}!               

  case 2:                    

   Console .Write ("");                    

   break;                

   default :                       

  Console.Write("");                 

    break;            

}            

Console.ReadLine();*/            

           /* //练习,判断2014年a月第b天是这一年的第几天        

     Console.WriteLine("输入月:");           

  int a = int.Parse(Console.ReadLine());          

   Console.WriteLine("输入日:");        

    int b = int.Parse(Console.ReadLine());                

   int c=1;

            switch (a)          

   {                 case 1:

                    c=b; //前面已经创建了int c,所以这里不能再创建int c=b,可以直接赋值即c=b.                        

                      break; 

                        case 2:                   

                        c = 31 + b;                

                       break;             

                       case 3:                  

                       c = 31 +28+ b;               

                         break;              

                          case 4:            

                        c = 31 + 28 +30+ b;             

                            break;

                          case 5:

                               c = 31 + 28 +31+30+ b;

                           break;

                           case 6:                     c = 31 + 28 +31+30+31+ b;                     break;                

                             case 7:                     c = 31 + 28 + 31 + 30 + 31 + 30 + b;                     break;                 case 8:                     c = 31 + 28 + 31 + 30 + 31 + 30 +31+ b;                     break;                 case 9:                     c = 31 + 28 + 31 + 30 + 31 + 30 + 31 +31 +b;                     break;                 case 10:                     c= 31 + 28 + 31 + 30 + 31 + 30 + 31 +31+30+ b;                     break;                 case 11:                     c = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 +31+ b;                     break;

                default:

                    c = 31 +28+31+30+31+30+31+31+30+31+30+ b;

                    break;

 }             //Console.Write("这是第" + c + "天");              //注意引用格式!

            Console.WriteLine("这是第" + c.ToString()  + "天");//.ToString()表示把引用的c转义为字符串型!     

 

        Console.ReadLine ();              */            

语句(switch case)

标签:os   ar   for   strong   sp   数据   2014   on   ad   

原文地址:http://www.cnblogs.com/huaze/p/4024182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!