Home > DeveloperSection > Forums > Cannot convert from int to Boolean using java
Kate Smith
Kate Smith

Total Post:24

Posted on    October-14-2013 3:40 AM

 Java Java 

 1 Reply(s)
 1897  View(s)
Rate this:
public static void main(String[] args) 
    int [] newArray= new int [4];
    int [] array = {4,5,6,7};
    newArray[0] = array[0]+array[1]+array[2]+array[3];
    newArray[1] = array[0]*array[1]*array[2]*array[3];
public static void oddEven(int [] oddEven)
    for (int i=0; i<oddEven.length; i++)
        if (oddEven[i] % 2)      //  Cannot convert from int to boolean

Ignore what I'm trying to manage here. I'm only curious why it doesn't accept "if" statement in this for loop. As I stated it says "cannot convert from int to boolean". Why do you think it says so?

Hank Greenberg
Hank Greenberg

Total Post:12

Posted on    October-14-2013 4:07 AM

That expression should be realizes an boolean in side the if, otherwise compilation error.

Try to this code: -

if (oddEven[i] % 2 ==0) 

 //Code Here

Don't want to miss updates? Please click the below button!

Follow MindStick