求助
帮忙看下下面这段代码的错误,多谢!~ C#的using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Clock
{
class Program
{
public abstract class Clock
{
public string hour { get; set; }
public string minute { get; set; }
public string second { get; set; }
public abstract void ShowTime(int _hour,int _minute,int _second);
}
public class TwentyFour : Clock
{
public override void ShowTime(int _hour, int _minute, int _second)
{
while (_hour >= 0 && _hour < 24)
{
if (_hour >= 0 && _hour <= 9)
{
this.hour = "0"+_hour;
}
else
{
this.hour = _hour.ToString();
}
}
while (_minute >= 0 && _minute < 60)
{
if (_minute >= 0 && _minute <= 9)
{
this.minute ="0"+ _minute;
}
else
{
this.minute = _minute.ToString();
}
}
while (_second >= 0 && _second < 60)
{
if (_second >= 0 && _second <= 9)
{
this.second ="0"+ _second;
}
else
{
this.second = _second.ToString();
}
}
}
}
//public void Twelve:Clock
//{
// public override void ShowTime(int _hour, int _minute, int _second)
// {
// }
//}
static void Main(string[] args)
{
Console.WriteLine("请输入时钟数:");
int H = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入分钟数:");
int M = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入秒钟数: ");
int S = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("您输入的时钟数为:" + H);
Console.WriteLine("您输入的分钟数为:" + M);
Console.WriteLine("您输入的秒钟数为:" + S);
TwentyFour tf = new TwentyFour();
tf.ShowTime(H, M, S);
Console.WriteLine("24小时制为:{0}:{1}:{2}", tf.hour, tf.minute, tf.second);
}
}
} --------------------编程问答-------------------- while (_hour >= 0 && _hour < 24)
while (_minute >= 0 && _minute < 60)
while (_second >= 0 && _second < 60)
把你这边的三个while改成if。
这是条件判断啊。 --------------------编程问答--------------------
牛人
补充:.NET技术 , C#