Int cannot be dereferenced error...
Hi , im having a weird int cannot be dereferenced error.. i have no idea what that means..
This is my program
publicclass Numbers
{
publicvoid display()
{
int sumeven=0;
int sumodd=0;
int sumneg=0;
int arr[]=newint[15];
for (int i=0;i<arr.length;i++)
{
if (arr[i].isPositiveEven==true)
{
System.out.print(arr[i]);
sumeven=sumeven+arr[i];
}
if (arr[i].isPositiveOdd==true)
{
System.out.print(arr[i]);
sumodd=sumodd+arr[i];
}
if (arr[i]><0)
{
System.out.print(arr[i]);
sumneg=sumneg+arr[i];
}
}
Sopln("Sum of Positive Even Numbers "+sumeven);
Sopln("Sum of Positive Odd Numbers "+sumodd);
Sopln("Sum of Negative Numbers "+sumneg);
}
privateboolean isPositiveEven(int n)
{
if (n>0 && n%2==0)
returntrue;
else
returnfalse;
}
privateboolean isPositiveOdd(int n)
{
if (n>0 && n%2!=0)
returntrue;
else
returnfalse;
}
}
[2780 byte] By [
Overkilla] at [2007-11-27 9:33:27]

Hello. This isn't what he meant by his post - every time you evaluate a boolean statement (i.e, in ifs,whiles etc.), you do not have to use "== true" in order to "ask" whether the statement is true - this is done automatically. As for your main question, you declared the methods "isPositiveOdd" and "isPositiveEven" in your class (Numbers). Since these methods are not static, they are part of each instance of the Numbers class which you will create - the do not belong to an int! Meaning, if you want to call these methods and pass an integer value to them, you're welcome, but when trying the say 5.isPositiveOdd(), you're just getting it wrong.
Also note that your subroutines can be simpler and more direct:
For example, your method:
private boolean isPositiveEven(int n)
{
if (n>0 && n%2==0)
return true;
else
return false;
}
Can be:
private boolean isPositiveEven(int n) {
return n>0 && n%2==0;
}