简体   繁体   English

错误:< 运算符未定义参数类型 Double[], double

[英]error: the < operator is undefined for the arguments type(s) Double[], double

I know this is quite basic but I am having trouble understanding to use < when testing against objects in an array.我知道这是非常基本的,但是在对数组中的对象进行测试时,我无法理解如何使用<

I want to test the ruleGrades which are stored in an 2D array against minimum (a double ), and then multiply it with a probability ( double ).我想针对minimumdouble ruleGrades测试存储在二维数组中的ruleGrades ,然后将其乘以probabilitydouble ruleGrades )。

ArrayList<Double[][]> ruleGrades  = new ArrayList<Double[][]>();
ArrayList<Double> min= new ArrayList<Double>();
double minimum;

System.out.println("Rule Grades: "+ruleGrades.toString());
        for(int a=0;a<ruleGrades.size();a++)
        {
            minimum=2.0;
            System.out.println("A: "+a);
            for(Double[] grades : ruleGrades.get(a))
            {
                if(grades<minimum) //error over here
                {
                    Double prob=rule.getRules().get(a).getProbability();
                    minimum=grades.doubleValue()*prob.doubleValue(); //error  
                }
            }
            min.add(minimum);
        }
        max=0.0; //finding largest
        for (int b = 0; b< min.size(); b++ )
        {
            if( min.get(b) > max)
            {
                max = min.get(b);
            }
        }
    }

UPDATE:更新:

Okay I see that i dont need a multidimensional array, I can just use a Double[] to have 2 values in the first element.好的,我知道我不需要多维数组,我可以只使用 Double[] 在第一个元素中有 2 个值。 Here is my updated code:这是我更新的代码:

ArrayList<Double[]> ruleGrades  = new ArrayList<Double[]>();
ArrayList<Double[]> min= new ArrayList<Double[]>();


System.out.println("Rule Grades: "+ruleGrades.toString());
        for(int a=0;a<ruleGrades.size();a++)
        {
            Double [] minimum={2.0,2.0};
            System.out.println("A: "+a);
            for(Double grades : ruleGrades.get(a))
            {
                if(grades<minimum[0])
                {
                    Double prob=rule.getRules().get(a).getProbability();
                    minimum[0]=grades.doubleValue()*prob.doubleValue();
                }
                if(grades<minimum[1])
                {
                    Double prob=rule.getRules().get(a).getProbability();
                    minimum[1]=grades.doubleValue()*prob.doubleValue();
                }
            }
            min.add(minimum);
        }
        Double [] max= {0.0,0.0}; //finding largest
        for (int b = 0; b< min.size(); b++ )
        {
            for(Double mins : min.get(b))
            {
                if( mins> max[0])
                {
                    max = min.get(b);
                }
            }   
        }
    }

So in my first IF statement I want to check if the first double is less than 2.0, then multiple it by the probability and then add it to the arraylist min.因此,在我的第一个 IF 语句中,我想检查第一个双精度值是否小于 2.0,然后将其乘以概率,然后将其添加到数组列表 min 中。

But how would I do that for the second value in the same element.但是我将如何为同一元素中的第二个值执行此操作。 For example ruleGrades contains: [1.7,1.9],[1.2,1.3] .... Then i take 1.7 multiply by prob (lets just say its 1) and add to the Double[] in the min arraylist, so min will look like this [1,7].例如 ruleGrades 包含: [1.7,1.9],[1.2,1.3] .... 然后我将 1.7 乘以 prob(让我们说它的 1)并添加到最小数组列表中的 Double[],所以 min 会看像这样 [1,7]。 But then I wish to the same for 1.9 and put it in the same element as 1.7, so then the min array will look like [1.7,1.9].但是我希望 1.9 也是如此,并将它放在与 1.7 相同的元素中,这样最小数组将看起来像 [1.7,1.9]。 Thats why i have added another IF statement , is this correct?这就是为什么我添加了另一个 IF 语句,这是正确的吗?

After all the grades have been multiplied by the prob and added to the min arraylist, i need to find the biggest one.在所有成绩乘以概率并添加到最小数组列表后,我需要找到最大的一个。 So i made a Double max[] is that correct ?所以我做了一个 Double max[] 对吗?

Sorry about this, I am trying to read but I am really confused.抱歉,我正在尝试阅读,但我真的很困惑。 Thanks for all the help so far.感谢到目前为止的所有帮助。

Actually you have declared array in inner for loop and comparing the whole array to a single double value.实际上,您已经在内部 for 循环中声明了数组,并将整个数组与单个双精度值进行比较。

grades < minimum is the problem grades < minimum是问题所在

for(Double[] grades : ruleGrades.get(a))
{
    if(grades is an array of Double < minimum is a double )  //error over here
     {

暂无
暂无

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

相关问题 错误:运算符 += 未定义参数类型 double, int[] - Error: The operator += is undefined for the argument type(s) double, int[] 对于参数类型boolean,double,运算符&gt;未定义 - The operator > is undefined for the argument type(s) boolean, double 运算符 -= 未定义参数类型 double, boolean - The operator -= is undefined for the argument type(s) double, boolean 对于double类型,EditText参数类型,未定义运算符* - The operator * is undefined for the argument type(s) double, EditText 运算符 += 未定义参数类型 double、Item - The operator += is undefined for the argument type(s) double, Item 对于参数类型double,Point2D.Double,运算符*未定义 - The operator * is undefined for the argument type(s) double, Point2D.Double 尚未为参数类型定义运算符* <String,Double> ,int - The operator * is undefined for the argument type(s) Map<String,Double>, int 我的项目java中的错误运算符-参数类型的字符串未定义 - error in my project java The operator - is undefined for the argument type(s) String, double 如何解决 main 类型中的方法 add(double, double, int, double) 不适用于参数 (double, double, double, double) - how to solve The method add(double, double, int, double) in the type main is not applicable for the arguments (double, double, double, double) Car Anylogic 类型未定义方法 getDistanceByRoute(double, double, double, double) - The method getDistanceByRoute(double, double, double, double) is undefined for the type Car Anylogic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM