20140818if语句

Posted on 2014-08-18 08:55  jack-jms  阅读(202)  评论(0编辑  收藏  举报

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("你太瘦了");

 

Copyright © 2024 jack-jms
Powered by .NET 8.0 on Kubernetes