MyMath

<pre name="code" class="csharp">{
    class Program
    {
        static void Main(string[] args)
        {
            Time t = new Time();
   
            try
            {
                Console.WriteLine("请输入小时");
                t.Hour = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请输入分钟");
                t.Minute = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请输入秒");
                t.Second = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
                return;
            }

            Time T = new Time();

            T.hour = DateTime.Now.Hour;
            T.minute = DateTime.Now.Minute;
            T.second = DateTime.Now.Second;



            Console.WriteLine("输入的时间为{0:00}:{1:00}:{2:00}", t.hour, t.minute, t.second);
            Console.WriteLine("当前的时间为{0:00}:{1:00}:{2:00}", T.hour, T.minute, T.second);
            t.DisPaly();
            T.DisPaly();




            Console.ReadKey();
        }
    }
    class Time
    {

        public int hour;
        public int minute;
        public int second;
        public int Hour
        {
            get
            {
                return Hour;
            }
            set
            {
                if (value > 0 && value < 24)

                    hour = value;


                else
                {
                    Console.Clear();
                    throw new Exception("输入的时间不正确");

                }
            }
        }

        public int Minute
        {
            get
            {
                return Minute;
            }
            set
            {
                if (value > 0 && value < 60)
                    minute = value;
                else
                {
                    Console.Clear();
                    throw new Exception("输入的时间不正确");
                }
            }
        }
        public int Second
        {
            get
            {
                return Second;
            }
            set
            {
                if (value > 0 && value < 60)
                    second = value;
                else
                {
                    Console.Clear();
                    throw new Exception("输入的时间不正确");
                }
            }
        }
        public int TimePeriod()
        {
            int a;
            a = hour * 3600 + minute * 60 + second;
            return a;
        }

        public void DisPaly()
        {
            Console.WriteLine("与零时刻的时间间隔:{0}",TimePeriod());

        }
    }
}  


 



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值