Java error Note: Operator can not be applied to boolean, int

Today wrote this code when learning the if statement:

        if( 3<= i<= 5 ){
            System.out.println("春天");
        }else if( 6 <= i  <= 8 ){
            System.out.println("夏天");
        }else if( 9 <=i  <=11 ){
            System.out.println("秋天");
        }else{
            System.out.println("冬天");
        };

Program error: Operator '<=' can not be applied to 'boolean', 'int'

The reason is that in Java if statement does not support such an expression. The correct expression should be

             if( 3<= i && i <= 5 ){
            System.out.println("春天");
        }else if( 6 <= i && i <= 8 ){
            System.out.println("夏天");
        }else if( 9 <=i && i <=11 ){
            System.out.println("秋天");
        }else{
            System.out.println("冬天");
        };

Way of writing the code complies with the specifications, should pay attention to.

Guess you like

Origin blog.51cto.com/14774208/2484815
Recommended