先贴今天的习题和练习代码:
习题按1~8编号 自己写的代码:
#region 练习1
Console.WriteLine("请输入姓名");
Console.ReadLine();
Console.WriteLine("请输入C#成绩");
double cSharp = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入Unity成绩");
double unity = Convert.ToDouble(Console.ReadLine());
string result = cSharp >= 90 && unity >= 90 ? "恭喜您毕业了" : "您学分不够暂未能毕业";
Console.WriteLine(result);
Console.WriteLine();
Console.WriteLine();
#endregion
#region 练习2
Console.WriteLine("请输入年份");
int year = Convert.ToInt32(Console.ReadLine());
string result2 = (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) ? "这一年是闰年" : "这一年不是闰年";//判断闰年
Console.WriteLine(result2);
Console.ReadKey();
#endregion
#region 练习3
Console.WriteLine("请输入第一个数:");
double input01 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入第二个数:");
double input02 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("最大值是:");
double result3 = input01 >= input02 ? input01 : input02;
Console.WriteLine(result3);
Console.WriteLine();
Console.ReadKey();
#endregion
#region 练习4
Console.WriteLine("请输入您的姓名:");
string name = Console.ReadLine();
string result4 = name == "老王" ? "警察" : "流氓";
Console.WriteLine(result4);
Console.ReadKey();
#endregion
#region 练习5
Console.WriteLine("请输入您的姓名:");
string name5 = Console.ReadLine();
Console.WriteLine("请输入您的年龄:");
int age5 = Convert.ToInt32(Console.ReadLine());
if (age5 >= 18)
{
Console.WriteLine(name5 + "可以看学习资料");
}
else
Console.WriteLine(name5 + "不可以看学习资料");
Console.ReadKey();
#endregion
#region 练习6
Console.WriteLine("请输入年龄:");
int age6 = Convert.ToInt16(Console.ReadLine());
if (age6 >= 23)
{
Console.WriteLine("你到了结婚年龄了");
}
else
Console.WriteLine("你还未到结婚年龄");
Console.ReadKey();
#endregion
#region 练习7
Console.WriteLine("请输入语文成绩:");
double chinese7 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入数学成绩:");
double math7 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入英语成绩:");
double english7 = Convert.ToDouble(Console.ReadLine());
if (((chinese7 > 70 && math7 > 80 && english7 > 90)) || (chinese7 == 100 || math7 == 100 || english7 == 100) || (chinese7 >= 90 && (math7 > 80 || english7 > 70)))
{
Console.WriteLine("非常棒!继续加油!");
}
else
Console.WriteLine("革命尚未成功,同志仍需努力!");
Console.ReadKey();
#endregion
#region 练习8
Console.WriteLine("请输入用户名:");
string admin = Console.ReadLine();
Console.WriteLine("请输入密码:");
string password = Console.ReadLine();
if (admin == "admin" && password == "123456")
{
Console.WriteLine("登陆成功!");
}
else
Console.WriteLine("登陆失败!");
Console.WriteLine();
Console.ReadKey();
#endregion