//输入老狼老狼几点了 Console.Write("老狼老狼几点了:"); string s = Console.ReadLine(); int hour = Convert.ToInt32(s); if(hour>=0&&hour<6) //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("输入时间错误!"); }
//输入三个数a,b,c.输出最大的. Console.Write("请输入一个数a:"); string a = Console.ReadLine(); Console.Write("请输入一个数b:"); string b = Console.ReadLine(); Console.Write("请输入一个数c:"); string c = Console.ReadLine(); int a1 = Convert.ToInt32(a); int b1 = Convert.ToInt32(b); int c1 = Convert.ToInt32(c); int s = a1 > b1 ? (a1 > c1 ? a1 : c1) : (b1 > c1 ? b1 : c1); Console.WriteLine("输出最大的是:" + s + "");
//输入一元二次方程的三个参数,a,b,c,判断根的情况。 Console.WriteLine("请输入a,b,c三个数"); Console.Write("输入a:"); int a=Convert.ToInt32(Console.ReadLine()); Console.Write("输入b:"); int b=Convert.ToInt32(Console.ReadLine()); Console.Write("输入c:"); int c=Convert.ToInt32(Console.ReadLine()); int d = b * b - 4 * a * c; if (a == 0) { Console.WriteLine("不是一元二次方程!"); } else { if (d > 0) { Console.WriteLine("方程有两个不相等的实数根。"); } else if (d == 0) { Console.WriteLine("方程有两个相等的实数根。"); } else { Console.WriteLine("方程无实数根。"); } }
//输入一个年份,判断是闰年。 Console.Write("请输入一个年份:"); int y = Convert.ToInt32(Console.ReadLine()); if (y > 0 && y < 9999) { if ((y % 400 == 0) || (y % 4 == 0 && y % 100 != 0)) { Console.WriteLine("是闰年"); } else { Console.WriteLine("不是闰年"); } } else { Console.WriteLine("输入的年份错误,请重新输入。"); }