编译通过,运行后只显示“按任意键继续”(C#语言) 15
bell类中程序:classBell{publicdelegatevoidchantime(doubletime);publiceventchantimechatimeE...
bell类中程序:
class Bell
{
public delegate void chantime(double time);
public event chantime chatimeEvent;
double time;
public void changetime()
{
for(double i=12.00;i<=15.00;i++)
{
time=i;
System.Threading.Thread.Sleep(1000);
if (time > 15.00)
{
chatimeEvent(time);
}
}
makealert类中程序:
class MakeAlert
{
public void makeAlert(double time)
{
Console.WriteLine("铛铛铛。。。已经{0}点了", time);
}
action中程序:
class Action
{
public void action(Double time)
{
Console.WriteLine("已经{0}点了,该上课去了!",time);
}
}
主程序:
class Program
{
static void Main(string[] args)
{
Bell bell = new Bell();
MakeAlert make = new MakeAlert ();
bell.chatimeEvent += make.makeAlert;
bell.changetime();
}
} 展开
class Bell
{
public delegate void chantime(double time);
public event chantime chatimeEvent;
double time;
public void changetime()
{
for(double i=12.00;i<=15.00;i++)
{
time=i;
System.Threading.Thread.Sleep(1000);
if (time > 15.00)
{
chatimeEvent(time);
}
}
makealert类中程序:
class MakeAlert
{
public void makeAlert(double time)
{
Console.WriteLine("铛铛铛。。。已经{0}点了", time);
}
action中程序:
class Action
{
public void action(Double time)
{
Console.WriteLine("已经{0}点了,该上课去了!",time);
}
}
主程序:
class Program
{
static void Main(string[] args)
{
Bell bell = new Bell();
MakeAlert make = new MakeAlert ();
bell.chatimeEvent += make.makeAlert;
bell.changetime();
}
} 展开
2个回答
展开全部
if (time > 15.00) 修改为 if (time == 15.00)或者 if (time >= 15.00)
更多追问追答
追问
为什么那么改呀
追答
你的for循环限制你的time最大也就15,而且你用的是double,其实15.00 == 14.99999999.....
所以严密的CPU下time==15.00也没法成立,只能是15-time < 0.0001 这样去判断,两个double值不可能相等,只能无限近似
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询