您的位置:首页 > 其它

条件语句实例

2015-08-02 20:38 169 查看
判断三个数谁对大:

static void Main(string[] args)
{
Console.WriteLine("请输入第一个数:");
int a = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("请输入第二个数:");
int b = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("请输入第三个数:");
int c = Convert.ToInt32(Console.ReadLine());

if (a >= b)
{
if (a >= c)
{
Console.WriteLine("三个数最大的是:" + a);
}

else
{
Console.WriteLine("三个数最大的是:" + c);

}

}
else
{

if (b >= c)
{
Console.WriteLine("三个数最大的是" + b);

}

else
{
Console.WriteLine("三个数最大的是" + c);
}
}

}


判断一个数的奇偶性:

static void Main(string[] args)
{
Console.Write("输入一个数:");
int a = int.Parse(Console.ReadLine());

if (a%2== 0)
{
Console.Write("这个数是偶数");
}
else
{
Console.Write("这个数是奇数");
}
Console.ReadLine();

}


判断闰年:

static void Main(string[] args)
{
Console.WriteLine("请输入年份:");
int year = int.Parse(Console.ReadLine());
if (year % 400 == 0 || year % 4 == 0 && year % 4 != 0)
{
Console.Write(year + "是闰年");

}
else
{
Console.Write(year+"是平年");
}
}


移动客服:

static void Main(string[] args)
{
Console.WriteLine("查话费按1,查流量按2,人工服务按3,业务办理按4,");
int a = Convert.ToInt32(Console.ReadLine());

switch (a)
{
case 1:
{
Console.WriteLine("你的话费有点多,禁止充值");
break;
}
case 2:
{
Console.WriteLine("流量还可以支撑");
break;
}
case 3:
{
Console.WriteLine("人工服务全忙,请稍候");
break;
}

case 4:
{
Console.WriteLine("对不起不能办理");
break;
}
default:
{
Console.WriteLine("您输入的有误");
break;
}

}
}


游戏随即英雄选择:

static void Main(string[] args)
{
Random a = new Random();
int b = a.Next(5);

string hero;

switch (b)
{
case 1:
{
hero = "伊泽瑞尔";
break;
}

case 2:
{
hero = "拉克丝";
break;
}

case 3:
{
hero = "盖伦";
break;
}

case 4:
{
hero = "提莫";
break;
}

default:
{
hero = "崔丝塔娜";
break;
}
}

Console.WriteLine("你选的英雄为:" + hero + ",请做好开始准备");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: