今天学了if 条件语句和作用域。作用域可以用一句话来概括:儿子可以用爹的所有东西,爹不可以用儿子的任何东西。If条件语句我用几个练习题来解释。

1、“请输入年份:”
判断是否是闰年,“xxxx年是闰年”,“xxxx年不是闰年”

namespace _2017_2_21
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入年份:");
int a=Convert.ToInt32(Console.ReadLine());
if(a>&&a<&&a%==&&a%!=||a%==)
{
Console.Write(a+"年是闰年");
}
else
{
Console.Write(a+"年不是闰年");
}
Console.ReadLine();
}
}
}

2、“请输入您的分数:”
小于0,大于100,“输入的分数有误!”
大于0,小于10,“不及格!学渣!”
小于60,“不及格!继续努力!”
大于等于60,“恭喜你!及格了!”
大于等于90,“学霸!很厉害!”

namespace _2017_2_21
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入您的分数:");
Double a=Convert.ToDouble(Console.ReadLine());
if(a<||a>)
{
Console.WriteLine("输入的分数有误!");
}
if(a>&&a<)
{
Console.WriteLine("不及格!学渣!");
}
if(a>=&&a<)
{
Console.WriteLine("不及格!继续努力!");
}
if(a>=&&a<)
{
Console.WriteLine("恭喜你!及格了!");
}
if(a>=&&a<=)
{
Console.WriteLine("学霸!很厉害!");
}
Console.ReadLine();
}
}
}

3、猜拳
“请输入您的手势(石头/剪子/包袱):”
“用户赢了” “电脑赢了” “平局”

namespace _2017_2_21
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入您的手势(石头/剪子/包袱):");
String you=Console.ReadLine();
Random n = new Random();
int a = n.Next(, );
Console.WriteLine(a); if ((you == "石头" && a == ) || (you == "剪子" && a == ) || (you == "包袱" && a == ))
{
Console.Write("你赢了");
}
else if((you=="石头"&&a==)||(you=="剪子"&&a==)||(you=="包袱"&&a==))
{
Console.Write("平了");
}
else
{
Console.Write("你输了");
}
Console.ReadLine();
}
}
}

4、人工智能对话
如果说的是同一句话,不一定要回复同一句

namespace _2017_2_21
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请说话:");
String a = Console.ReadLine();
Random n = new Random();
int g = n.Next(, );
if (g == )
{
Console.WriteLine("哈哈");
}
else if (g == )
{
Console.WriteLine("嘻嘻");
}
else if (g == )
{
Console.WriteLine("你好");
}
else if (g == )
{
Console.WriteLine("汪汪");
}
else if (g == )
{
Console.WriteLine("hello");
}
Console.ReadLine();
}
}
}

1、“请输入年份:”(1-9999)
“请输入月份:”(1-12)
“请输入日期:”(要判断大小月,判断闰年)
判断输入的时间日期是否正确

2、计算输入的时间是当前这一年的第几天


namespace _2017_2_22作业1
{
class Program
{
static void Main(string[] args)
{int year, month, date,num;
Console.WriteLine("请输入年份:(1-9999)");
year=Convert.ToInt32(Console.ReadLine());
if (year >= && year <= )
{
Console.WriteLine("请输入月份:");
month = Convert.ToInt32(Console.ReadLine());
if (month >= && month <= )
{
Console.WriteLine("请输入日期:");
date = Convert.ToInt32(Console.ReadLine());
if (month == || month == || month == || month == || month == || month == || month == && date >= && date <= )
{
Console.WriteLine("您输入的日期格式正确");
if(month==)
{
num = date;
Console.WriteLine("您输入的日期是当年的第"+num+"天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天"); }
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + ++date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + +++ date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
} if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + + + ++ date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
} if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + + + ++++ date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + + + ++++++ date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + ++++++date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
} else if ((month == || month == || month == || month == ) && date >= && date <= )
{
Console.WriteLine("您输入的日期格式正确");
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + ++date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month == )
{
num = + + + + + +++ date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
if ((year >= && year <= && year % == && year % != || year % == ) && month ==)
{
num = + + + + + + + + ++ date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
} else if ((year >= && year <= && year % != || year % == || year % != ) && month == )
{
num = + + + + + + + + + + date;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
}
else if ((year >= && year <= && year % == && year % != || year % == ) && month == && date >= && date <= )
{
Console.WriteLine("您输入的日期格式正确");
num = + ;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
}
else if ((year >= && year <= && year % != || year % == || year % != ) && month == && date >= && date <= )
{
Console.WriteLine("您输入的日期格式正确");
num = + ;
Console.WriteLine("您输入的日期是当年的第" + num + "天");
} else
{
Console.WriteLine("您输入的日期格式不对");
}
}
else
{
Console.WriteLine("您输入的月份格式错误");
}
}
else
{
Console.WriteLine("您输入的年份格式错了");
}
Console.ReadLine(); }
}
}

3、标准体重
男士体重 = 身高 - 100 +-3
kg cm
女士体重 = 身高 - 110 +-3

namespace _2017_2_22标准体重
{
class Program
{
static void Main(string[] args)
{Console.WriteLine("请输入您的性别");
String sex=Console.ReadLine();
Console.WriteLine("请输入您的体重");
int weight = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入您的身高");
int height =Convert.ToInt32( Console.ReadLine());
if (sex == "男" && (height - weight - >= - || height - weight - <= ))
{
Console.WriteLine("您的体重是标准体重");
}
else
{
if (height - weight - < -)
{
Console.WriteLine("您超重");
}
if (height - weight - >)
{
Console.WriteLine("您偏瘦");
}
Console.ReadLine();
}
if (sex == "女" &&( height - weight - >= - || height - weight - <= ))
{
Console.WriteLine("您的体重是标准体重");
}
else
{
if (height - weight - < -)
{
Console.WriteLine("您超重");
}
if (height - weight - > )
{
Console.WriteLine("您偏瘦");
}
Console.ReadLine();
}
}
}
}

4、猜拳将用户的手势和电脑的手势输出出来

namespace _2017_2_22猜拳游戏显示手势
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入您的手势(石头/剪子/包袱):");
String you = Console.ReadLine();
Random n = new Random();
int a = n.Next(, ); if (a==)
{
Console.WriteLine("石头");
}
if (a == )
{
Console.WriteLine("剪子");
}
if (a == )
{
Console.WriteLine("包袱");
} if ((you == "石头" && a == ) || (you == "剪子" && a == ) || (you == "包袱" && a == ))
{
Console.Write("你赢了");
}
else if ((you == "石头" && a == ) || (you == "剪子" && a == ) || (you == "包袱" && a == ))
{
Console.Write("平了");
}
else
{
Console.Write("你输了");
}
Console.ReadLine();
}
}
}

5、“请输入24小时制的时间:”
0-24 如果超出“时间输入有误”

namespace _2017_2_22时间24小时制转变成12小时制
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入24小时制的时间:");
int a =Convert.ToInt32( Console.ReadLine());
if(a>||a<)
{
Console.WriteLine("输入的时间有误");
}
if(a<=&&a>)
{
Console.WriteLine("上午"+a+"点");
}
if(a<=)
{
Console.WriteLine("凌晨" + a + "点");
}
int b = a - ;
if(a>&&a<)
{
Console.WriteLine("下午" + b + "点");
}
if(a==)
{
Console.WriteLine("凌晨0点");
} Console.ReadLine();
}
}
}

2017-2-21 C#基础 if条件语句,作用域的更多相关文章

  1. JAVA基础——Switch条件语句

    JAVA基础——switch 条件语句 switch语句结构: switch(表达式){ case值1: 语句体1: break: case值2: 语句体2: break: case值3: 语句体3: ...

  2. Python基础、条件语句和基本数据类型

    1. 第一句python - 后缀名是可以是任意? - 导入模块时,如果不是.py文件 ==> 以后文件后缀名是 .py 2. 两种执行方式 python解释器 py文件路径 python 进入 ...

  3. VBS基础篇 - 条件语句

    经常地,当我们编写代码时,我们需要根据不同的判断执行不同操作,我们可以使用条件语句完成这个工作. If...Then...Else 在下面的情况中,您可以使用 If...Then...Else 语句: ...

  4. Python新手学习基础之条件语句——if/else语句

    if/else语句 条件语句实际在前面的文章里我们已经使用过几次了,在这里我们需要再次隆重的来介绍一下它,条件语句是通过对一条或多条语句判断的返回结果(True或False)来选择执行下一步命令的,比 ...

  5. Python基础之条件语句和循环

    条件语句 Python中的条件语句分为 if ...else . if ...elif...else  以及if ...else 的嵌套使用: username = input('请输入您的用户名:' ...

  6. 【Python基础】条件语句

    Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非空(null)值为tr ...

  7. python学习-4 python基础-2 条件语句(if的简单用法1)

    条件语句的原理: 2.举个例子:比大小 #!/usr/bin/env python # -*- coding:utf8 -*- a=input("请输入a:") b=input(& ...

  8. js基础(条件语句 循环语句)

    条件语句 if语句块的语法形式如下: //只有两种情况下if(条件){要执行的语句块;}else{要执行的语句块;} //多种情况下if(条件){要执行的语句块;}else if(条件){要执行的语句 ...

  9. Java入门 - 语言基础 - 10.条件语句

    原文地址:http://www.work100.net/training/java-if-else.html 更多教程:光束云 - 免费课程 条件语句 序号 文内章节 视频 1 概述 2 if...e ...

随机推荐

  1. java系列--JSON数据的处理

    http://blog.csdn.net/qh_java/article/details/38610599 http://www.cnblogs.com/lanxuezaipiao/archive/2 ...

  2. Swift去除两边的特定字符(空格或其它)

    var str_trim = "   !hi  !23   !" str_trim.stringByTrimmingCharactersInSet(NSCharacterSet.w ...

  3. iOS 之 OC开发实战

    iOS 开发之登陆 iOS 程序初始一个带导航栏的视图 iOS 添加导航栏两侧按钮 iOS UITabBar

  4. [c#]解决方案:需要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping。

    问题详情 如下图所示(部分): 出现该错误,是因为应用程序中需要使用到jquery(现在的web应用程序哪个能离开jquery呢),而目前程序目录中并没有jquery文件,或者有jquery文件但是程 ...

  5. WinAPI: GetClassName - 获取指定窗口的类名

    WinAPI: GetClassName - 获取指定窗口的类名 //声明: GetClassName( hWnd: HWND; {指定窗口句柄} lpClassName: PChar; {缓冲区} ...

  6. jQuery的each函数

    http://www.cnblogs.com/xiaojinhe2/archive/2011/10/12/2208740.html http://www.cnblogs.com/mabelstyle/ ...

  7. C# winform项目中ListView控件使用CheckBoxes属性实现单选功能

    C# winform项目中ListView控件使用CheckBoxes属性实现单选功能 在做项目时需要使用ListView控件的CheckBoxes属性显示,还要在点击行时自动选中CheckBoxes ...

  8. 如何从mysql中将数据导入到sqlserver

    本文讨论如何把MySQL的数据库导入到SQL Server中,所以首先你需要把两种数据库都安装了,再进行以下步骤. 一.为 MySQL安装ODBC驱动 1. 下载MySQL ODBC Connecto ...

  9. Spring context:component-scan代替context:annotation-config

    Spring context:component-scan代替context:annotation-config XML: <?xml version="1.0" encod ...

  10. HDU5842

    Lweb and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...