# you cant do var.length - 1?

• 03-15-2012, 09:48 PM
javanubby
you cant do var.length - 1?
Got an incompatible type error...
Code:

```public static double mean (int x[ ]){         int total = 0;         for (int i=1; x.length - 1; i++)             total = total + x[i];         return (total/x.length-1);     } //end method mean```
• 03-15-2012, 09:54 PM
JosAH
Re: you cant do var.length - 1?
x.length-1 is an int expression; you need a boolean expression for the 'for-condition' part; you probable meant:

Code:

```for (int i= 1; i < x.length-1; i++)   // ...```
kind regards,

Jos
• 03-15-2012, 09:59 PM
raj kumar singh
Re: you cant do var.length - 1?
You have done mistake in for loop,
at the place of condional statement(i.e. x.lingth - 1).
To overcome this error,
either,you have to give any boolean type value or any conditional statement there,
then only the error can be removed.
as like...

for (int i=1; i< x.length ; i++)
total = total + x[i];
• 03-15-2012, 10:28 PM
javanubby
Re: you cant do var.length - 1?
ah thanks guys