zoukankan      html  css  js  c++  java
  • .net(三个简单的作业)

    1,读入一个小数,将小数部分和整数部分交换:例如 3.14 ---〉14.3

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TestExchange
    {
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
                    // 1,从控制台读入一个小数,存放在 testDouble 中
                    string testDouble = Console.ReadLine();
    
                    // 2,转为double 类型
                    double result;
    
                    // 用try ... catch ... 语句捕获格式错误的异常
                    try
                    {
                        result = double.Parse(testDouble);
    
                        // 3,将testDouble以‘.’隔开
                        string[] splitStr = testDouble.Split('.');
    
                        // 4,格式输出
                        Console.WriteLine("{0}.{1}", int.Parse(splitStr[1]), int.Parse(splitStr[0]));
    
                    }
                    catch (FormatException e)
                    {
                        // 捕获数字格式不正确的异常
                        Console.WriteLine("输入数字格式不正确");
                    }
                    catch (System.IndexOutOfRangeException e)
                    {
                        // 捕获全部整数不包含小数点的异常
                        Console.WriteLine("输入的数应包含小数点");
                    }
                }
            }
        }
    }
    


     

    2,定义一个qq状态的枚举(在线、隐身、离线)。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TestQQState
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
        }
    
        // 定义QQ状态的枚举
        enum QQState
        {
            OnLine,     //在线
            OffLine,    //离线
            Hidding,    //隐身
            Busy        //忙碌
        }
    }
    


    3, 老婆给当程序员的老公打电话:“下班顺路买10个包子,如果看到卖西瓜的,买一个。”下班后,老公买回一个包子,因为他看到卖西瓜的了,老婆气晕了。分别用程序表达这句话的意思:老婆的意思;程序员老公理解的意思。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TestJok
    {
        class Program
        {
            static void Main(string[] args)
            {
                Husband husband = new Husband();
    
                // 买包子的个数
                int bzCount;
    
                // 买西瓜的个数
                int xgCount;
    
                // 是不是有买西瓜的
                bool isThereHasXiGua = false;
    
                // 老婆的意思
                husband.getOffWork();       // 老公下班
                husband.buyBaozi(10);       // 老公买十个包子
                if (isThereHasXiGua == true) // 如果看到卖西瓜的
                {
                    husband.buyXiGua(1);    // 买一个西瓜
                }
                
                //老公的意思
                husband.getOffWork();           // 老公下班
                if (isThereHasXiGua == false)    // 如果没有看到买西瓜的
                {
                    husband.buyBaozi(10);       // 买 10 个包子
                }
                else                            // 如果看到卖西瓜的
                {
                    husband.buyBaozi(1);        // 买 1 个包子
                }
    
            }
        }
    
        /// <summary>
        /// Husband 类
        /// </summary>
        class Husband
        {
            /// <summary>
            /// 买包子的方法
            /// </summary>
            /// <param name="bzCount">买的包子的个数</param>
            public void buyBaozi(int bzCount)
            {
            }
    
            /// <summary>
            /// 下班的方法
            /// </summary>
            public void getOffWork() 
            { 
            }
    
            /// <summary>
            /// 买西瓜的方法
            /// </summary>
            /// <param name="xgCount">买的西瓜的个数</param>
            public void buyXiGua(int xgCount)
            {
            }
        }
    }
    


  • 相关阅读:
    C#基础篇——泛型
    基于.NetCore3.1系列 —— 使用Swagger导出文档 (补充篇)
    基于.NetCore3.1系列 —— 使用Swagger导出文档 (番外篇)
    springboot深入浅出系列(16章97节)-看了都说好
    小书MybatisPlus第5篇-Active Record模式精讲
    小书MybatisPlus第4篇-表格分页与下拉分页查询
    使用位运算、值交换等方式反转java字符串-共四种方法
    有效提高java编程安全性的12条黄金法则
    小书MybatisPlus第3篇-自定义SQL
    结合SpEL使用@Value-基于配置文件或非配置的文件的值注入-Spring Boot
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671596.html
Copyright © 2011-2022 走看看