java - Why did I get a "bad operand types for binary operator" error? -


i working on exercise incorporates 1 method another. know getminmax() method has empty array that's irrelevant purpose of exercise.

code:

public class square{     int area;      public square[] getminmax(square[][] arr){         square[] list = new square[2];         return list;     }      public int getarea(){         return area;     }      public boolean isdifferencesignificant(square[][] arr){         boolean isit = false;         square [] result = getminmax (arr);         if((result[1] - result[0])< 0.5) //the line (16) in question             isit = true;         return isit;     } } 

when compile following error:

square.java:16: error: bad operand types binary operator '-'         if((result[1] - result[0])< 0.5)                       ^   first type:  square   second type: square 1 error 

i'm lost , want know why error occurred.

edit: rohit jain said "you meant - result[1].getarea() - result[0].getarea()"

and lochemage said "if((result[1].getarea() - result[0].getarea())< 0.5)"

both of these work , thank time!

i assume want test area variable of each square instead?

if((result[1].getarea() - result[0].getarea())< 0.5) 

by doing result[1] - result[0] invoking binary subtraction operator square class, may not defined.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -