江上雨
2019-11-25 15:03
if (x >= y)
{
if (x >= 5)
Console.WriteLine("5");
}
else if (y >= 6)
Console.WriteLine("6");
else
Console.WriteLine("7");
vs里就可以!
else if 后面也要加{}
static void Main(string[] args)
{
int x = 5;
int y = 6;
if (x >= y)
{ if (x >= 5)
Console.WriteLine("5");}
else
{ if (y >= 6)
Console.WriteLine("6");
else
Console.WriteLine("7");
}
}
因为慕课里的这个程序是死板的,只要你和他写的流程不一样就会报错呀,其实你的程序是没有错的,但是你也不能那样写,因为规范的代码的话,if 、else、else if 等都是需要加 {} ,这个的,因为我们做开发以后代码是要给别人读的,所以从开始的时候养成良好的编程的习惯会对我们有帮助!所以你在你的程序加上{}看看还报错不。
{
if (x >= 5)
Console.WriteLine("5");
}
你的第二个括号用的是中文全角},要用英文半角}
你试试把括号加全试试,我也没看出来
C#开发轻松入门
256615 学习 · 1528 问题
相似问题