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]
# 1
Primitives don't have any methods or fields, so you can't do something like this:arr[i].isPositiveEvenarr is an array of ints, so arr[ i] is an int, and has no isPositiveEven field.
hunter9000a at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 2
I didnt quite understand..
Overkilla at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 3
You want:if(isPositiveOdd(arr[ i ])) {
malcolmmca at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 4
So when i use arrays i dont have to type ==true , and i type it in that way..K thanksBut can you explain why?
Overkilla at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 5

It has nothing to do with arrays. There has to be a boolen value inside those parenthesis, and whether it's

true

true == true

someBool == true

or

someBool

or

someMethodCallThatReturnsABoolean()

doesn't matter

CeciNEstPasUnProgrammeura at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 6

What malcolmmc suggested in more obvious:

int number = arr[i];

boolean isOdd = isOdd(number);

if (isOdd) {

// magic here

No difference between "isOdd == true" and "isOdd", or would there be in your opinion?

CeciNEstPasUnProgrammeura at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 7

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.

laginimaineba at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...
# 8

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;

}

BigDaddyLoveHandlesa at 2007-7-12 22:55:05 > top of Java-index,Java Essentials,Java Programming...