我的代码出了什么问题?我得到2个方法预期错误 [英] what's wrong with my code? i'm getting 2 method expected errors

查看:77
本文介绍了我的代码出了什么问题?我得到2个方法预期错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace For1_100EvenOdd
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int i = 0; i <= 100; i++)

                if
                    (i ((i%2) == 0))// declare as even
                {
                    Console.WriteLine("It's even");
                }// end if
                 else if
                    (i((i%2) == 1))// declare i as odd
                {
                    Console.WriteLine("It's odd");
                }// end if else
        }
    }
} // end For1-100EvenOdd

推荐答案

试试这个:
for (int i = 0; i <= 100; i++)
{
    if (i%2 == 0)// declare as even
    {
        Console.WriteLine("It's even");
    }// end if
    else
    {
        Console.WriteLine("It's odd");
    }// end if else
}


你的第一个问题是你应该学习语言语法。



你的第二个问题是你忽略了对你的帮助由编译器提供。

与新手,错误信息和位置问题的强烈信念相反,并且是有帮助的。



改善你的问题错误消息
Your first problem is that you should really learn the language syntax.

Your second problem is that you neglect the help you have been given by compiler.
Contrary to the strong believe among newbies, error messages and position matters and are help.

Improve your question with the error messages


令牌 i 出现在几个奇怪的地方。



另外,为什么在其他中有



您可能还想了解三元运算符。
The token i appears in a couple of odd places.

Plus, why do you have an if in the else?

You might also want to learn about the ternary operator.


这篇关于我的代码出了什么问题?我得到2个方法预期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆