任务19:118-接受用户输入的字符串,整数和小数
    接受用户输入的字符串,整数和小数

    1. string str1 = Console.ReadLine();
    2. int num1 = Convert.ToInt32(str1);
    3. Console.WriteLine(str1);

    任务20:119-案例练习:接受用户从控制台输入的两个数字,并计算和,输出到控制台

    1. try
    2. {
    3. Console.WriteLine("please input first number");
    4. string str1 = Console.ReadLine();
    5. Console.WriteLine("please input second number");
    6. string str2 = Console.ReadLine();
    7. double num1 = Convert.ToDouble(str1);
    8. double num2 = Convert.ToDouble(str2);
    9. Console.WriteLine("{0}+{1}={2}", num1, num2, num1 + num2);
    10. }
    11. catch
    12. {
    13. Console.WriteLine("error");
    14. }

    任务21:120-赋值运算符
    赋值运算符
    image.png
    任务22:121-运算符的优先级
    运算符的优先级

    • 不需要特别去记
    • 用括号改变优先级

    任务23:122-练习1和2
    练习2:接受用户输入的两个整数,交换变量存储的值

    1. string str1 = Console.ReadLine();
    2. string str2 = Console.ReadLine();
    3. int num1 = Convert.ToInt32(str2);
    4. int num2 = Convert.ToInt32(str1);

    任务24:123-练习3和4
    练习3:要求用户输入4个int值,返回他们的乘积

    1. string x1 = Console.ReadLine();
    2. string x2 = Console.ReadLine();
    3. string x3 = Console.ReadLine();
    4. string x4 = Console.ReadLine();
    5. Console.WriteLine(Convert.ToInt32(x1) * Convert.ToInt32(x2) * Convert.ToInt32(x3) * Convert.ToInt32(x4));

    练习4:输入一个三位整数,倒序输出

    1. string str = Console.ReadLine();
    2. int a = Convert.ToInt32(str);
    3. int x = a % 10; //取得个分位
    4. int y = (a- a % 10- (a - a % 100)) / 10; //取得十分位
    5. int z = (a - a % 100) / 100; //取得百分位
    6. Console.WriteLine("{0}{1}{2}",x,y,z);
    1. string str = Console.ReadLine();
    2. int a = Convert.ToInt32(str);
    3. int x = a % 10; //取得个分位
    4. int y = (a / 10) % 10; //取得十分位
    5. int z = a / 100; //取得百分位
    6. Console.WriteLine("{0}{1}{2}",x,y,z);

    任务25:124-练习5和6
    练习5:输入梯形上底,下底和高,输出面积

    1. string str1 = Console.ReadLine();
    2. string str2 = Console.ReadLine();
    3. string str3 = Console.ReadLine();
    4. double a = Convert.ToInt32(str1);
    5. double b = Convert.ToInt32(str2);
    6. double h = Convert.ToInt32(str3);
    7. Console.WriteLine((a+b)*h/2);

    练习6:计算半径为n的圆的周长和面积
    (略)

    任务26:125-初识布尔运算(比较运算)
    流程控制

    • 分支:有条件的执行代码
    • 循环:重复执行代码

    布尔运算

    • bool

    任务27:126-布尔运算符
    布尔运算符
    image.png
    任务28:127-条件布尔运算符和取反运算符
    布尔运算符-处理布尔值(只需要掌握第一个)
    image.png
    条件布尔运算符
    image.png