• c#案例


    输入年月日 验证
    
    int year, mou, data;
    Console.Write("请输入一个日期:年:");
    string y = Console.ReadLine();
    Console.Write("月:");
    string m = Console.ReadLine();
    Console.Write("日:");
    string d = Console.ReadLine();
    year = Convert.ToInt32(y);
    mou = Convert.ToInt32(m);
    data = Convert.ToInt32(d);
    if ((year > 0000 & year < 9999) & )
    {
    if ((mou > 0 & mou <= 12) & (mou == 1 || mou == 3 || mou == 5 || mou == 7 || mou == 8 || mou == 10 || mou == 12))
    {
    if (data > 0 & data <= 31)
    {
    Console.WriteLine("您输入的" + year + "" + mou + "" + data + "日是正确日期");
    }
    else if ((data > 0 & data <= 30) & (mou == 4 || mou == 6 || mou == 9 || mou == 11))
    {
    Console.WriteLine("您输入的" + year + "" + mou + "" + data + "日是正确日期");
    if ((data > 0 & data <= 28) & (mou == 2))
    {
    Console.WriteLine("您输入的" + year + "" + mou + "" + data + "日是正确日期");
    }
    else
    {
    Console.WriteLine("您输入的日期错误");
    }
    }
    else
    {
    
    Console.WriteLine("您输入的日期错误");
    }
    
     
    
    }
    else
    {
    Console.WriteLine("您输入的日期错误");
    }
    }
    else if ((year > 0000 & year < 9999) & (year % 4 == 0 & year % 100 != 0) || (year % 400 == 0))
    {
    if (mou == 2)
    {
    if (data > 0 & data <= 29)
    {
    Console.WriteLine("您输入的" + year + "" + mou + "" + data + "日是正确日期");
    }
    else
    {
    Console.WriteLine("您输入的日期错误");
    }
    
    }
    else
    {
    Console.WriteLine("您输入的日期错误");
    }
    }
    else
    {
    Console.WriteLine("您输入的日期错误");
    }
    
    测缘分
    
    Console.Write("男方姓名:");
    string mr = Console.ReadLine();
    Console.Write("女方姓名:");
    string miss = Console.ReadLine();
    Random rank = new Random();
    int yuan = rank.Next(100);
    if(yuan>=0&yuan<=10)
    {
    Console.WriteLine("缘分指数"+yuan+",5百年只能换来回眸一笑");
    }
    else if (yuan > 10 & yuan <= 30)
    {
    Console.WriteLine("缘分指数" + yuan + ",百年修得同船渡");
    
    }
    else if (yuan > 30 & yuan <= 50)
    {
    Console.WriteLine("缘分指数" + yuan + ",只能做一夜夫妻");
    
    }
    else if (yuan > 50 & yuan <= 70)
    {
    Console.WriteLine("缘分指数" + yuan + ",7年之痒");
    }
    else if(yuan>70&yuan<=90)
    {
    Console.WriteLine("缘分指数" + yuan + ",白头偕老");
    }
    else if (yuan>90&yuan<=100)
    
    {
    Console.WriteLine("缘分指数" + yuan + ",人鬼情未了");
    }
    else
    {
    Console.WriteLine("缘分指数" + yuan + ",不同物种");
    }
    1.输入圆柱体底面积半径和高,求体积。
    
    const double p = 3.14;
    Console.WriteLine("请输入圆柱体的底面积半径:");
    string r = Console.ReadLine();
    Console.WriteLine("请输入圆柱体的高:");
    string h = Console.ReadLine();
    double R=Convert.ToDouble(r);
    double H=Convert.ToDouble(h);
    
    
    Console.WriteLine("圆柱体的体积是:"+p*R*R*H);
    
    2建造游泳池 泳池半径a 广场半径b 输入a和b 求泳池的护栏长度   广场砖的面积  护栏的花费  广场砖的花费
    
    const double p=3.14;
    Console.WriteLine("请输入游泳池的半径:");
    string a = Console.ReadLine();
    double A = Convert.ToDouble(a);
    
    Console.WriteLine("泳池的护栏长度是:"+p*A*2+"");
    
    Console.WriteLine("护栏的造价是:"+25*p*A*2+"");
    Console.WriteLine("请输入广场半径:");
    string b = Console.ReadLine();
    
    double B = Convert.ToDouble(b);
    Console.WriteLine("广场砖的面积是:" +(p*B*B-p*A*A)+ "平方米");
    
    Console.WriteLine("广场砖花费"+85*(p*B*B-p*A*A)+"");
    
    3老狼几点了
    
    Console.Write("老狼老狼几点了");
    string s = Console.ReadLine();
    int hour = Convert.ToInt32(s);
    if (hour >= 0 && hour < 6)
    {
    Console .WriteLine ("凌晨"+hour+"点了");
    }
    else if (hour >= 6 && hour <= 12)
    { 
    Console .WriteLine("上午"+hour+"点了");
    }
    else if (hour > 12 && hour < 18)
    { 
    hour-=12;
    Console .WriteLine("下午"+hour+"点了");
    }
    else if (hour >= 18 && hour <= 24)
    {
    hour -= 12;
    Console.WriteLine("晚上"+hour+"点了");
    }
    else
    {
    Console.WriteLine("你家有"+hour+"点啊?");
    }
    
    4称体重。男人的标准体重是:体重(kg)=身高(cm)-100.
    女人的标准体重是:体重(kg)=身高(cm)-110.
    上下浮动3公斤属于正常。
    要求输入 性别 身高和体重,输出正常,偏旁 偏瘦。
    
    Console.Write("性别(男,女):");
    string sex=Console .ReadLine ();
    Console.Write("体重:");
    string k1 = Console.ReadLine();
    double k2 = Convert.ToDouble(k1);
    
    Console .Write("身高:");
    string c=Console .ReadLine ();
    double cm=Convert.ToDouble(c);
    double kg=cm-100;
    
     
    
    if (sex == "")
    {
    
    if (k2 >= kg-3 && k2 <= kg+3)
    {
    Console.WriteLine("恭喜你,你是猛男身材!");
    
    }
    
    else
    {
    if (k2 > kg+3)
    {
    Console.WriteLine("狗熊,你偏重了");
    }
    else
    {
    Console .WriteLine ("猴子, 你太瘦了");
    }
    }
    }
    else if(sex=="")
    {
    kg=cm-110;
    if (k2 >= kg-3 && k2 <= kg+3)
    {
    Console.WriteLine("恭喜你,你是魔鬼身材!");
    
    }
    
    else
    {
    if (k2 > kg+3)
    {
    Console.WriteLine("母猪,你偏重了");
    }
    else
    {
    Console .WriteLine ("野鸡, 你太瘦了");
    }
    }
    
    
    }
    else
    {
    Console .WriteLine("你是外星人吗");
    }
    
    5.输入a b c 3个数 求最大
    
    //int a, b, c, d, max;
    //Console.WriteLine("请输入a,b,c,找出那个最大");
    //string a1 = Console.ReadLine();
    //string b1 = Console.ReadLine();
    //string c1 = Console.ReadLine();
    //a = Convert.ToInt32(a1);
    //b = Convert.ToInt32(b1);
    //c = Convert.ToInt32(c1);
    //d = a > b ? a : b;
    //max = d > c ? d : c;
    //Console.WriteLine("最大的数是:" + max);
    
    6 判断一元二次方程跟的情况 
    
    int a1 ,b1,c1,d;
    Console.Write("判断一元二次方程式的根的情况,输入a=");
    string a = Console.ReadLine();
    Console.Write("输入b=");
    string b = Console.ReadLine();
    Console.Write("输入c=");
    string c = Console.ReadLine();
    
    a1 = Convert.ToInt32(a);
    b1 = Convert.ToInt32(b);
    c1 = Convert.ToInt32(c);
    
    d=b1*b1-4*a1*c1;
    if(a1==0)
    {
    Console.WriteLine("这不是一元二次方程");
    }
    else if(d>0) 
    {
    Console.WriteLine("有2个不同实跟");
    }
    else if (d == 0)
    {
    Console.WriteLine("有2个相同的实根");
    }
    else 
    {
    Console.WriteLine("没有实根");
    }
    
    7 闰年 平年判断
    
    Console.Write("请输入一个年份(0000-9999):");
    string y = Console.ReadLine();
    int year = Convert.ToInt32(y);
    
    if (((year % 4 == 0 & year % 100 != 0) || (year % 400 == 0)) & (year > 0000 & year < 9999))
    {
    Console.WriteLine(year+"年是闰年");
    }
    else if ((year % 4 != 0 || (year % 400 != 0)) & (year > 0000 & year < 9999))
    {
    Console.WriteLine(year+"年是平年");
    }
    else
    {
    Console .WriteLine ("您输入的年份错误");
    }


  • 相关阅读:
    pycharm2017.3.7的安装
    SVN Working Copy xxx locked 并 cleanup失败之解
    Lua查找字符串注意
    Lua运算符
    Python操作Excel
    项目中碰到的Ajax相关的问题记录
    线程的相关概念
    val()用法和value的区别
    JSON数组对象和JSON字符串的转化,map和JSON对象之间的转化
    算法复杂度相关概念
  • 原文地址:https://www.cnblogs.com/w297613932/p/4178883.html
Copyright © 2020-2023  润新知