24小时制转化为12小时制(if语句简单练习)

namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int t,n;
            Console.Write("请输入24小时制时间:");
            t = Convert.ToInt32(Console.ReadLine());
            if (t>0&&t<6)
            {
               Console.WriteLine("现在时间是凌晨:"+t+"");  
            }
            else if (t==0||t==24)
            {
               
                Console.WriteLine("现在时间是凌晨:0时");

            }
            else if (t >=6 && t <= 12)
            {

                Console.WriteLine("现在时间是上午:" + t + "");
            }
            else if (t > 12 && t <= 18)
            {
                n = t - 12;
                Console.WriteLine("现在时间是下午:" + n + "");

            }
            else if (t>12&&t<=18)
            {
                n = t - 12;
                Console.WriteLine("现在时间是下午:" + n+"");
  
            }
            else if (t >18 && t <= 23)
            {
                n = t - 12;
                Console.WriteLine("现在时间是晚上:" + n + "");

            }
         
            else
            {
                Console.WriteLine("请输入正确的时间!" );
            }
            }
            
        }
    }
}

 

posted @ 2015-03-28 09:09  Yusarin  阅读(431)  评论(0编辑  收藏  举报