• 练手


     1             Console.Write("请输入第一个数:");
     2             string a = Console.ReadLine();
     3             int a1 = Convert.ToInt16(a);
     4             
     5             Console.Write("请输入第二个数:");
     6             string b = Console.ReadLine();
     7             int b1 = Convert.ToInt16(b);
     8             
     9             Console.Write("请输入+/-");
    10             string c = Console.ReadLine();
    11 
    12             int x1 = a1 + b1;
    13             int y1 = a1 - b1;
    14             string x = Convert.ToString(x1);
    15             string y = Convert.ToString(y1);
    16             
    17             
    18             
    19             string jia=(c=="+")?x:y;
    20             Console.Write(jia);
    21             
    22 
    23             Console.ReadLine();
    1             Console.Write("请输入一个0~100的整数:");
    2             string a1 = Console.ReadLine();
    3             int a = Convert.ToInt16(a1);
    4             string b = a < 50 || a == 66 ? "" : "";
    5             Console.Write(b);
    6 
    7 
    8 
    9             Console.ReadLine();
    1             Console.Write("请输入您的成绩(0~100):");
    2             string a = Console.ReadLine();
    3             double a1 = Convert.ToDouble(a);
    4 
    5             string b = a1 >= 60 ? "及格了!" : "不及格,继续努力!";
    6             Console.Write(b);
    7 
    8             Console.ReadLine();
     1             Console.Write("请输入一个100内的整数:");
     2             string a = Console.ReadLine();
     3             int b = (int.Parse(a)) % 7;
     4             string c = b == 0 ? "" : "不是";
     5             int a1 = (int.Parse(a));
     6             string d = a1 >= 70 && a1 < 80 ? "" : "不是";
     7             int a2 = (int.Parse(a));
     8             int b1 = (int.Parse(a)) % 10;
     9             string e = b1 == 7 ? "" : "不是";
    10 
    11 
    12             Console.WriteLine(""+"是不是7的倍数:"+c+"");
    13             Console.WriteLine(""+"十位数是不是7:"+d+"");
    14             Console.WriteLine(""+"个位数是不是7:"+e+"");
    15 
    16           
    17             
    18             Console.ReadLine();
    19         }

     下面这个是上面第一个的简化版  也是思路最清晰的一种方法

     1             Console.Write("请输入第一个数:");
     2             double a = Convert.ToDouble(Console.ReadLine());
     3 
     4 
     5             Console.Write("请输入第二个数:");
     6             double b = Convert.ToDouble(Console.ReadLine());
     7 
     8 
     9             Console.Write("请输入字符(+/-)");
    10             char c = Convert.ToChar(Console.ReadLine());
    11             char c1 = '+';
    12 
    13 
    14             double d = c == c1 ? a + b : a - b;
    15             Console.WriteLine(d);
    16             Console.ReadLine();

     下面这个是上面第二个练习小题的另一种思路,核心思路不一样,但是套路相同

    1             Console.Write("请输入一个0~100的整数:");
    2             string a1 = Console.ReadLine();
    3             int a = Convert.ToInt16(a1);
    4             string b = a >= 50 && a != 66 ? "" : "";
    5             Console.Write(b);
    6 
    7 
    8 
    9             Console.ReadLine();
  • 相关阅读:
    含字母的数字排序
    ci中简单实用的权限管理
    时间戳和日期转换
    prop
    定时器
    centos查看防火墙策略是firewall还是iptables
    centos上安装rabbitmq服务器
    springcloud微服务feign消费模式解决 com.netflix.client.ClientException: Load balancer does not have available server for client:xxx
    java正则去掉json字符串key的引号
    centos安装redis
  • 原文地址:https://www.cnblogs.com/TheJoker/p/6419545.html
Copyright © 2020-2023  润新知