这是一个C#新人的学习笔记---3

160 阅读2分钟

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace ConsoleApp4 { internal class Program { static void Main(string[] args) { //变量 数据类型 整形int 浮点型double 字符串string 字符char 布尔bool int a = 2; //变量名的命名规则 不能以数字开头,大小写字母,数字,下划线组成 Console.Read();//返回的是字符 Console.ReadLine();//返回的是字符串

        Console.WriteLine();//有默认的换行符
        Console.Write("asd");//没有自带的换行符

        //运算符 + - * / % 赋值运算符 = *= /= += -= %= a*=b => a=a*b
        //关系运算符 > >= <= < != ==
        //逻辑运算符 &&与 ||或 !非取反  结果是一个布尔值
        Console.WriteLine(true || false);
        //三目运算符  式子?值1:值2  当式子结果为真则返回值1,否则返回值2
        //类型转换 强转 Convert
        string str = "2";
        int num = 1;
        num = Convert.ToInt32(str);

        //条件分支
        //双分支 两种情况
        /*if (判断条件)
        {
            执行语句1;//当条件为真则执行此语句
        }
        else
        {
            执行语句2;
        }*/
        //多分支 很多种情况
        /*if (num>2) 
        {
            Console.WriteLine(1);
        }else if(num>3)
        {
            Console.WriteLine(2);
        }else if(num>4)
        {
            Console.WriteLine(3);
        }
        else
        {
            Console.WriteLine(4);
        }

        if (num == 2) Console.Write(2);//如果只有一条执行语句的时候括号可以省略
        Console.WriteLine(num);*/

        Console.WriteLine("请输入您的考试成绩");
        int score = Convert.ToInt32(Console.ReadLine());
        if (score >= 90)
        {
            Console.WriteLine("您的评级为:A");
        }
        else if (score >= 80)
        {
            Console.WriteLine("您的评级为:B");
        }
        else if (score >= 70)
        {
            Console.WriteLine("您的评级为:C");
        }
        else if(score >= 60)
        {
            Console.WriteLine("您的评级为:D");
        }
        else
        {
            Console.WriteLine("不及格");
        }
        //x,y x=0,y=0原点 x>0,y>0第一象限  x>0,y<0第四象限 x<0,y>0第二象限 x<0,y<0第三象限
        Console.WriteLine("请输入x");

        int x = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("请输入y");
        int y = Convert.ToInt32(Console.ReadLine());
        if (x==0 && y == 0)
        {
            Console.WriteLine("原点");
        }
        else if(x > 0 && y > 0)
        {
            Console.WriteLine("第一象限");
        }
        else if (x > 0 && y < 0)
        {
            Console.WriteLine("第二象限");
        }
        else if (x < 0 && y > 0)
        {
            Console.WriteLine("第三象限");
        }
        else
        {
            Console.WriteLine("第四象限");
        }
        //switch 分支语句
        /* switch(比对的值) 值1 值2都是执行同一个执行语句
          {
            case 值1:
                执行语句;
            break;
             case 值2:
                执行语句;
            break;
             case 值3:
                执行语句;
            break;
             case 值4:
                执行语句;
            break;
            ...
            default:
                默认执行语句;
            break;
        }*/

        //每星期的日程
        string day = Console.ReadLine();
        switch (day)
        {
            case "星期一":
            case "monday":
                Console.WriteLine("有点舒服");
                break;
            case "星期二":
            case "tuesday":
                Console.WriteLine("很舒服");
                break;
            case "星期三":
                Console.WriteLine("超级难受");
                break;
            case "星期四":
                Console.WriteLine("很难受");
                break;
            case "星期五":
                Console.WriteLine("难受");
                break;
            case "星期六":
                Console.WriteLine("嘿嘿嘿");
                break;
            case "星期日":
                Console.WriteLine("嘿嘿");
                break;

        }
        //练习  输入4个整数,求出其中的最大值和最小值,并输出出来
        int a1 = Convert.ToInt32(Console.ReadLine());
        int max = a1;
        int min = a1;
        int a2 = Convert.ToInt32(Console.ReadLine());
        if (a2 > max) max = a2;
        if (a2 < min) min = a2;
        int a3 = Convert.ToInt32(Console.ReadLine());
        if (a3 > max) max = a3;
        if (a3 < min) min = a3;
        int a4 = Convert.ToInt32(Console.ReadLine());
        if (a4 > max) max = a4;
        if (a4 < min) min = a4;
        Console.WriteLine("最大值是{1}最小值是{0},max,min");
    }

}

}