c sharp 的输入,输入,switch语句。

创建一个控制台应用程序,从键盘输入一个小写字母,要求输出该小写字母,其对应的大写字母,以及值。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("put  small  char:");
            char ch1 =Convert.ToChar( Console.ReadLine());
            while (!(ch1 >= 'a' && ch1 <= 'z'))
            {
                Console.WriteLine("put  small  char:");
                ch1 = Convert.ToChar(Console.ReadLine());
            }
            char ch2=(char)(ch1-('a'-'A'));
            Console.WriteLine("{0},{1},{2}", ch1, ch2, (int)ch1);

        }
    }
}
put  small  char:
a
a,A,97
请按任意键继续. . .

创建一个控制台程序,随机产生二个小数,计算它们对应的和,商,差,积。

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            Random random = new Random();
            double a = random.NextDouble() * 1000; //生成0-1000之间的随机小数。
            double b = random.NextDouble() * 100;  //生成0-100之间的随机小数。
            Console.WriteLine("a={0} ,b={1}", a, b);
            Console.WriteLine("a+b={0}", caculat(a, b,'+'));
            Console.WriteLine("a-b={0}", caculat(a, b, '-'));
            Console.WriteLine("a*b={0}", caculat(a, b, '*'));
            Console.WriteLine("a/b={0}", caculat(a, b, '/'));

        }

        static double caculat(double a, double b,char operate)
        {
            double end = 0;
            switch (operate)
            {
                case '+':
                    end = a + b;
                    break;
                case '-':
                    end = a - b;
                    break;
                case '*':
                    end = a * b;
                    break;
                case '/':
                    end = a / b;
                    break;
                default:
                    Console.WriteLine("has error");
                    break;   
            }

            return end;
        }

    }
}
a=699.086446174926 ,b=39.3562914055569
a+b=738.442737580483
a-b=659.73015476937
a*b=27513.4498933355
a/b=17.7630163109378
请按任意键继续. . .
点赞