Member 11104762 Ответов: 1

Как удалить ошибку 'bad operand types for binary operator '==' 'в этой программе?


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();
        }
    }


Что я уже пробовал:

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


Этот оператор показал ошибку bad operand types for operating system ==. first type int; second type object.

Leo Chapiro

По-видимому, это сообщение об ошибке говорит о том, что вы не можете сравнить "int" с "object", ну и что?

1 Ответов

Рейтинг:
1

CPallini

Сообщение об ошибке довольно ясно: вы не можете сравнить Object с int.
Если вы уверены, что low1 коллекция на самом деле содержит ints, затем бросьте его правильно, например

int x = (int)low1.get(a);
for (int i = 0; i < row; i++) {
  if (dc[i][a] == x) {
    i1.add(i);
  }
}

Кстати, было бы лучше использовать универсальные коллекции (то есть ArrayList<E>[^]).


Member 11104762

int x = (int)low1.get(a); с помощью этой ошибки объект is не может быть преобразован в int.

CPallini

Какую версию Java вы используете?

Member 11104762

Спасибо вам сэр с помощью ArrayList sloved эта ошибка