如何在这个程序中删除'二元运算符'==''的'坏操作数类型'的错误? [英] How can remove the error of 'bad operand types for binary operator '==' 'in this program?

查看:68
本文介绍了如何在这个程序中删除'二元运算符'==''的'坏操作数类型'的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package cloude;

import java.io.*;
import java.lang.management.*;
import java.text.*;
import java.util.*;


public class Cloude6 {

    static int dir, row = 10, col = 12, r = -1;
    static int dcr[][];
    static int dc[][] = {{8, 7, 5, 7, 8, 5, 9, 7, 8, 6, 6, 7}, {5, 7, 9, 5, 4, 8, 4, 9, 4, 8, 8, 5}, 
                         {9, 6, 8, 7, 9, 5, 6, 9, 7, 6, 7, 7}, {8, 7, 4, 3, 6, 3, 2, 6, 5, 4, 6, 4}, 
                         {6, 3, 2, 4, 7, 8, 5, 3, 5, 5, 4, 5}, {8, 6, 9, 7, 9, 7, 5, 8, 8, 7, 8, 7}
                        };
    static DecimalFormat df = new DecimalFormat("#.##");
    static double fcr[][];
    static int low, max, row1;
    static ArrayList l1 = new ArrayList();
    static ArrayList low1 = new ArrayList();
    static HashSet i1 = new HashSet();
    static ArrayList i2 = new ArrayList();
    static int g = 0;
    static ArrayList fuzzy = new ArrayList();
    static int user, g1 = 0;
    static double fin[];

    public static void main(String[] args) {
        ThreadMXBean TMB = ManagementFactory.getThreadMXBean();
        long time = new Date().getTime() * 1000000;
        long cput = TMB.getCurrentThreadCpuTime();
        double cpuperc = -1;
        long lStartTime = new Date().getTime();
        try {
            getDirectory();
            for (int p = 1; p <= dir; p++) {
                l1.removeAll(l1);
                low1.removeAll(low1);
                i1.removeAll(i1);
                i2.removeAll(i2);
                
                showValues();
                for (int j = 0; j < col; j++) {
                    findLowest(j);
                }
                System.out.println(l1);
                for (int j = 0; j < col; j++) {
                    showEquals(j);
                }
                i2.addAll(i1);
                System.out.println(i2);
                selectedMatrix();
                showUpdated();
                fcr = new double[row1][col];
                for (int i = 0; i < col; i++) {
                    findMax(i);
                }
                showFinal();
                for (int i = 0; i < row1; i++) {

                    additionFcr(i);
                }
            }

            System.out.println(fuzzy);
            usersInput();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        if (TMB.isThreadCpuTimeSupported()) {
           
            cpuperc = (TMB.getCurrentThreadCpuTime() - cput) / (new Date().getTime() * 1000000.0 - time) * 100;
            System.out.println("Cpu Utilization: " + cpuperc);
        } else {
            cpuperc = -2;
        }

        long lEndTime = new Date().getTime(); //end time

        long difference = lEndTime - lStartTime; //check different

        System.out.println("Elapsed milliseconds: " + difference);
    }

    public static void usersInput() throws IOException {
        user=5;
        System.out.println("Enter the Number of Users" + user );
   
        for (int x = 1; x <= user; x++) {
            int d = fuzzy.size();
            fin = new double[d];
            Object ob[] = fuzzy.toArray();
            for (int a = 0; a < ob.length; a++) {
                String str = ob[a].toString();
                fin[a] = Double.valueOf(str).doubleValue();
            }
            double ss = fin[0];
            for (int i = 0; i < ob.length; i++) {
                if (ss < fin[i]) {
                    ss = fin[i];
                    g1 = i;
                }
            }
            System.out.println("User " + x + "  =  " + ss);
            fuzzy.remove(ss);
            System.out.println(fuzzy);
        }
    }

    public static void additionFcr(int a) throws IOException {
        double x = 0;
        for (int j = 0; j < col; j++) {
            x += fcr[a][j];
        }
        fuzzy.add(x);
        System.out.println("This is The Final Fuzzy Value " + a + " = " + df.format(x) + "\t");
    }

    public static void showFinal() throws IOException {
        System.out.println("Information About CSP & Parameters");
        for (int i = 0; i < row1; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(df.format(fcr[i][j]) + "\t\t");
            }
            System.out.println();
        }
    }

    public static void findMax(int a) throws Exception {
        max = dcr[0][a];
        for (int i = 0; i < row1; i++) {
            if (max < dcr[i][a]) {
                max = dcr[i][a];
            }
        }
        System.out.println("The Best Service Provided in col " + a + " = " + max);

        for (int j = 0; j < row1; j++) {
            fcr[j][a] = (float) dcr[j][a] / max;
        }

    }

    public static void showUpdated() throws IOException {
        System.out.println("Information About CSP & Parameters");
        System.out.println("The Twelve Non-funtional Parameters like Virtualization, Application Security, Data Operation, Legal Issues,"
                + "Risk Management, Compliance and Audit, Interperability and Portability, "
                + "Business Continuity and Disaster Recovery, Data Center Operations, Incident Resposne, "
                + "Key Management, Identity Entitlement and Access Management ");
        for (int i = 0; i < row1; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(dcr[i][j] + "\t");
            }
            System.out.println();
        }
    }

    public static void selectedMatrix() throws IOException {
        int a = i1.size();
        int x = 0, n = 0, w = 0;
        row1 = row - a;
        dcr = new int[row1][col];
        outer:
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                for (int k = 0; k < a; k++) {
                    n = (Integer) i2.get(k);
                    if (n == i) {
                       
                        continue outer;
                    }
                }
                dcr[x][j] = dc[i][j];
            }
            x++;
        }
    }

    public static void showEquals(int a) throws IOException {
        Object x = low1.get(a);
        for (int i = 0; i < row; i++) {
            if (dc[i][a] == x) {
                i1.add(i);
            }
        }
    }

    public static void findLowest(int a) throws Exception {
        low = dc[0][a];
        for (int i = 0; i < row; i++) {
            if (low > dc[i][a]) {
                low = dc[i][a];
                r = i;
            }
        }
        if (r == -1) {
            r = 0;
        }
        if (r != -1) {
            l1.add(r);
            low1.add(low);
        }
        r = -1;
        System.out.println("The Thrashold Value in col " + ++a + " = " + low);
    }

    public static void showValues() throws IOException {
        System.out.println("Information About CSP & Parameters");
         System.out.println("The Twelve Non-funtional Parameters like Virtualization, Application Security, Data Operation, Legal Issues,"
                + "Risk Management, Compliance and Audit, Interperability and Portability, "
                + "Business Continuity and Disaster Recovery, Data Center Operations, Incident Resposne, "
                + "Key Management, Identity Entitlement and Access Management ");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(dc[i][j] + "\t");
            }
            System.out.println();
        }
    }





我的尝试:





What I have tried:

if (dc[i][a] == x)





此语句显示操作系统错误操作数类型==。第一种类型int;第二种类型的对象。



This statement shown an error bad operand types for operating system ==. first type int; second type object.

推荐答案

错误信息非常清楚:您无法将对象 int

如果您确定 low1 集合实际上包含 int s,然后正确投射,例如

The error message is pretty clear: you can't compare an Object with an int.
If you are sure the low1 collection actually contain ints, then cast it properly, e.g.
int x = (int)low1.get(a);
for (int i = 0; i < row; i++) {
  if (dc[i][a] == x) {
    i1.add(i);
  }
}



顺便说一句,它会更好地使用泛型集合(即 ArrayList< E> [ ^ ])。


这篇关于如何在这个程序中删除'二元运算符'==''的'坏操作数类型'的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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