首页 > 代码库 > 20140818if语句

20140818if语句

if语句

大体可以分一下几种:

例:

 //跟电脑猜拳             Console.Write("请出拳");             string human = Console.ReadLine();             Console.WriteLine("人VS电脑");

            Random a = new Random();             int x = a.Next(3);             String computer;             if (x == 0)             {                 computer = "剪刀";             }             else if (x == 1) ;             {                 computer = "拳头";             }             else                 computer = "布";

 

            Console.WriteLine(human + "VS" + computer);             int b = 3;             if (human ! = "剪刀"&&human !"拳头"&&human !"布" )             {                  Console.WriteLine("输入错误");             }             else if(human == "剪刀")             {              b = 0;             }             else if(human == "拳头")             {              b = 1;             }             else                 b =2;

 

           if ((b - x == 1)||(b - x == 2))            {                Console.WriteLine("你赢了");            }             else if ((b - x == 1)||(b - x == 2))            {              Console.WriteLine("你输了");             }             else if ((b == x )             {             Console.WriteLine("再来一次吧");             }             else                 Console.WriteLine("输入错误");

 

 

 

 

 

 

 

 

 

 

 

 //体重称量器             Console.Write("请输入您的体重");             bool eals= Convert.ToBoolean( Console.ReadLine());             Console.Write("请输入您的身高");             bool HHH= Convert.ToBoolean( Console.ReadLine());             Console.Write("请输入您的性别");             bool xxx = Convert.ToBoolean(Console.ReadLine());             if (xxx == true)             {                 int s = HHH - 100;                 if (eals > (s + 3));                 {                     Console.Write("胖");                 }                 else if ((eals < = (s +3 )&&(eals>=s-3)))                 {                 Console.Write("正常");                 }                 else                     Console.Write("你太瘦了");             }             else                 int s=HHH - 110                 if(eals > (s + 3));             {                     Console.Write("胖");             }

              else if((eals < = (s +3 )&&(eals>=s-3)))               {                Console.Write("正常");               }               else                    Console.Write("你太瘦了");