偶值得纪念的一天-初学习C#

                  今天好悲催啊,竟然生病啦,不过一切还好!

                  今天我们在云和数据学习的第二天,上午没有听课,似乎学习了变量的定义以及命名方法,还有变量类型的显隐式转换;我感觉这些还是在之前看书知道啦把,因此看啦看老师做的笔记以及写的程序例子也就好啦。

 下午三点赶来上课了,学习了if···else···分支语句的用法:下面就是我们的课下练习,我已经完成了,就随意记录下吧!

                    程序如下:

                   <1> 写下判断闰年的表达式,设待判断的年份变量为year,润年的判定(符合下面两个条件之一):年份能够被400整除或者年份能够被4整除但不能被100整除.让用户输入一个年份,如果是润年,则输出true,如果不是,则输出false.          

复制代码
 class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个年份");
            string  year =Console.ReadLine();
            int year1 = Convert.ToInt32(year);

            bool a = year1 % 400 == 0;
            bool b = year1 % 4 == 0 && year1 % 100 != 0;
            if (a)
            {
                Console.WriteLine(a);
                Console.ReadKey();
            }
            else if (b)
            {
                Console.WriteLine(b);
                Console.ReadKey();
            }
            else
            {
                Console.ReadKey(false);
            }

        }
    }
复制代码

           <2>让用户输入年龄,如果输入的年龄大于23(含)岁,则给用户显示你到了结婚的年龄了.

复制代码
 class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入您的年龄:");
            string  age = Console.ReadLine();
            int age1 = Convert.ToInt32(age);
            if (age1 > 23)
            {
                Console.WriteLine("你到了结婚的年龄了.");
                Console.ReadKey();
            }
        }
    }
复制代码

             <3>如果老苏的(chinese  music)语文成绩大于90并且音乐成绩大于80或者语文成绩等于100并且音乐成绩大于70,则奖励100元.

复制代码
 class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入您的语文成绩:");
            string chinesecore = Console.ReadLine();

            Console.WriteLine("请输入您的音乐成绩:");
            string music = Console.ReadLine();
          
            int chinesecore1 = Convert.ToInt32(chinesecore);
            int music1 = Convert.ToInt32(music);

            if (chinesecore1 > 90 && music1>80)
            {
                Console.WriteLine("奖励你100元.");
                Console.ReadKey();
            }
            else if (chinesecore1 ==100 && music1 >70)
            {
                Console.WriteLine("奖励你100元.");
                Console.ReadKey();
            }
        }
    }
复制代码

                 <4>让用户输入用户名和密码,如果用户名为admin,密码为mypass,则提示登录成功.

复制代码
 class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入用户名:");
            string username = Console.ReadLine();

            Console.WriteLine("请输入密码:");
            string pwd = Console.ReadLine();

            bool a = username == "admin" && pwd == "mypass";
            if (a)
            {
                Console.WriteLine("登录成功");
                Console.ReadKey();
            }
        }
    }
复制代码

            <5>老苏买了一筐鸡蛋,如果坏蛋少于5个,他就吃掉,否则他就去退货

复制代码
 class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("老苏买一筐鸡蛋,其中坏蛋的个数:");
            string eggs = Console.ReadLine();

            int eggs1 = Convert.ToInt32(eggs);
            if (eggs1 > 5)
            {
                Console.WriteLine("请您吃掉这一筐鸡蛋");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("您去退货吧");
                Console.ReadKey();
            }
        }
    }
复制代码

                <6>要求用户输入两个数a、b,如果a和b整除或者a加b大于100,则输出a的值,否则输出b的值

复制代码
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入两个数:");
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            int a1 = Convert.ToInt32(a);
            int b1 = Convert.ToInt32(b);
            if (a1 % b1 == 0 || a1 + b1 > 100)
            {
                Console.WriteLine("{0}", a1);
            }
            else
            {
                Console.WriteLine("{0}", b1);
            }
            Console.ReadKey();
        }
    }
复制代码

                  <7>对学员的结业考试成绩评测(考虑用if好还是用if-else好)

                       成绩>=90 :A     

                      90>成绩>=80 :B  

                      80>成绩>=70 :C

                      70>成绩>=60 :D

                       成绩<60  :E

复制代码
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入学员的考试成绩:");
            string sore = Console.ReadLine();
            int sore1 = Convert.ToInt32(sore);
            if (sore1 >= 90)
            {
                Console.WriteLine("A");
                Console.ReadKey();
            }
            else if (sore1<90 && sore1 >=80)
            {
                Console.WriteLine("B");
                Console.ReadKey();
            }
            else if (sore1 < 80 && sore1 >= 70)
            {
                Console.WriteLine("C");
                Console.ReadKey();
            }
            else if (sore1 < 70 && sore1 >= 60)
            {
                Console.WriteLine("D");
                Console.ReadKey();
            }
            else if (sore1 < 60)
            {
                Console.WriteLine("E");
                Console.ReadKey();
            }
            Console.ReadLine();
            Console.ReadKey();
        }
    }
复制代码

           这是今天练习的几个,还有好几个例子,我要继续努力了额1

posted @   雪?  阅读(616)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示