Tom Darshan
Tom Darshan

Reputation: 11

Hard time finding an error in my code

I have some problems with my java code here. When I try to compile I get the error:

"bad operand types for binary operator '&&'" for the if statement

which I usually get when I made an error in the boolean logic. For the past half hour I've tried to find the mistake in my code but I'm not able to find it. Any pointers?

code below

public String toString(){
    double x1 = this.ecke1.getX();
    double y1 = this.ecke1.getY();
    double x2 = this.ecke2.getX();
    double y2 = this.ecke2.getY();
    double[] Y = {y1,y2,0};
    double[] X = {x1,x2,0};
    for (int y = 0; y <= Utils.max(y1,y2,0); y++)
        for(int x = 0; x <= Utils.max(x1,x2,0); x++)
            if (   ((x=0) && (y=0) ) || (  ( (y/x) <= (Utils.min(X)/Utils.max(Y)) ) && ( (y/x) >= (Utils.min(Y)/Utils.max(X)) ) && ( (y/x) <= ((Utils.max(Y)-Utils.min(Y)) / (Utils.min(X) - Utils.max(X))) )  )   )  
                System.out.print("#");
            else system.out.print("-");
}

Upvotes: 1

Views: 52

Answers (3)

Yougansh Thakur
Yougansh Thakur

Reputation: 338

= is an assignment operator while == is a comparison operator. So you need to use x == 0 && y == 0.

Upvotes: 0

Danish Ansari
Danish Ansari

Reputation: 447

Use double equal to sign(==) instead of single(=)

if (((x==0) && (y==0) )...)

You use single equal sign for assignment and double for comparison.

Upvotes: 0

Eran
Eran

Reputation: 393771

Change

(x=0) && (y=0)

to

(x==0) && (y==0)

x=0 is an assignment, so it doesn't evaluate to a boolean. x==0 is a comparison, and returns a boolean.

Upvotes: 3

Related Questions