将j设置为大于-等于 [英] setting j greater-then or equal to

查看:97
本文介绍了将j设置为大于-等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在行"j> = j * n"时遇到了一些问题
我收到以下错误:

I''m having some problems with the line "j >= j * n"
I get the following error:

Only assignment, call, increment, decrement, and new object expressions can be used as a statement.


我正在尝试增加 j .


and I am trying to, increment, j.

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

namespace Functions
{
    public class Factorial
    {
        // The "Calc" static method calculates the factorial value for the
        // specified integer passed in:
        public static int Calc(int i)
        {
            return ((i <= 1) ? 1 : (i * Calc(i - 1)));
        }
    }
}

namespace infini
{
    class infini
    {   
        static void Main(string[] args)
        {
            int n;
            int j;
            n = 3;

            Dictionary<string, int> d =
new Dictionary<string, int>();

            d.Add("A1", 0);

            List<int> range = new List<int>();
            for (int i = 1; i > 0; i++)
            {
                j = 1 - d["A1"] / Calc(n) ;
                while ((i * j) < 1)
                {
                    j >= j * n;
                }
            }

     

            
        }

        private static int Calc(int n)
        {
            throw new NotImplementedException();
        }

        public static int Factorial { get; set; }
    }
}

推荐答案

您收到的错误是因为您实际上没有做"任何事情,只检查即可.
> =表示检查是否大于或等于.它不会改变j.
要增加j,您需要根据需要使用类似以下的内容.

The error you get is because you don''t actually ''do'' anything, you only check.
>= means check if greater than, or equal to. It does not change j.
To inclement j you need to use something like below, depending on what you need to do.

j = j + 1; //Add 1 to j, and store that in j
j += 1; //Add one to j, and store it in j (shorthand notation)
j++; //Increment j with 1 (even shorter shorthand notation)

//Or with n

j += n; //Add n to j, and store in j(same as j = j + n)
j *= n; //Multiply j with n, and store in j (same as j = j * n)



希望这对您有所帮助,如果没有,请随时发表评论.



Hope this helps you on your way, if not, feel free to post a comment.


错误消息很清楚:
The error message is clear:
j >= j * n;


不是有效的声明.
您正在尝试做什么(您知道,您可以只使用(有效)语句


is NOT a valid statement.
What are you trying to do (you know, you may just use the (valid) statement

j++;


用于递增j).


顺便说一句,没有 设置j大于或等于i" ,但只有 测试j是否大于或等于i" (至少在我所知道的编程语言中).


for incrementing j).


BTW there is NO "setting j greater than or equal to i", but only "testing if j is greater or equal to i" (at least in the programming languages I know).


前面已经说过,j >= j * n严格等同于n <= 1 || j == 0,它更有效,因为第二部分在大多数情况下可能不被检查或不需要包含在表达式中,因为第二部分在代码中是这样定义的. >
—SA
In addition to what was already said, j >= j * n is strictly equivalent to n <= 1 || j == 0, which is more effective because the second part may not be checked in most cases or need not to be included in the expression because it is so defined in code.

—SA


这篇关于将j设置为大于-等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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