Cannot convert from int to boolean?

后端 未结 1 2025
迷失自我
迷失自我 2021-01-29 02:25
public static void main(String[] args) {
    int [] newArray= new int [4];
    int [] array = {4,5,6,7};
    oddEven(array);

    newArray[0] = array[0]+array[1]+array[2         


        
相关标签:
1条回答
  • 2021-01-29 02:34

    That expression in side the if should be realizes to boolean value, otherwise compilation error in java.

    Try

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

    or even (based on requirment)

           if (oddEven[i] % 2 !=0)  {
           }
    

    See the Language Specification# chapter 14

    The Expression must have type boolean or Boolean, or a compile-time error occurs.

    0 讨论(0)
提交回复
热议问题