简体   繁体   English

如何检查多个动态数字等于另一个dyanami数字

[英]how to check multiple of a dynamic number to equal to another dyanami number

if (numberContentUnits % 4 == 0 == quantity >= 4){
    getAddToCartMethod(code, quantity);
}

here i want check dynamically numberContentUnits and quantity .i don't want take 4 like static vlaue could please anyone help me... 在这里我想要动态检查numberContentUnitsquantity 。我不想拿4像静态vlaue可以请任何人帮助我...

I cannot understand the question exactly, but want to help you. 我无法完全理解这个问题,但想帮助你。 Here is a simple of possible examples from your question: 以下是您问题中可能的简单示例:

Case 1. 情况1。

public class NewClass2 {

    public static void main(String[] args) {
        int quantity = 10;
        int code = 5;
        int four = 4;
        for (int numberContentUnits = 0; numberContentUnits < 50; numberContentUnits++) {
            if (numberContentUnits % four == 0 == quantity >= 4) {
                int res = getAddToCartMethod(code, quantity);
                System.out.println("Res: " + res);
            }
        }

    }

    private static int getAddToCartMethod(int code, int quantity) {
        return code + quantity;
    }
}

As you can see you can your "4" * variable four ) is not static. 正如你所看到的,你的“4”* variable four是不是静态的。

Case 2. 案例2。

public class NewClass2 {

    static int four = 4;

    public static void main(String[] args) {
        int quantity = 10;
        int code = 5;
        for (int numberContentUnits = 0; numberContentUnits < 50; numberContentUnits++) {
            if (numberContentUnits % four == 0 == quantity >= 4) {
                int res = getAddToCartMethod(code, quantity);
                System.out.println("Res: " + res);
            }
        }

    }

    private static int getAddToCartMethod(int code, int quantity) {
        return code + quantity;
    }
}

Here it is already static. 这里已经是静态的了。 What is your question? 你的问题是什么?

I am not exactly sure about the expected outcome of this code. 我不完全确定此代码的预期结果。

int val = 4; //you have an option of taking this value as method parameter
if ( (numberContentUnits % val == 0) && (quantity >= val) ){
    getAddToCartMethod(code, quantity); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM