Java错误笔记:Operator cannot be applied to boolean,int

今天在学习 if 语句时写下了这样一段代码:app

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("冬天");
        };

程序报错:Operator '<=' cannot be applied to 'boolean','int'ide

缘由是Java中 if 语句不支持这样的表达方式。正确的表达方式应该为 学习

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("冬天");
        };

代码的书写方式应该符合规范,理应注意。code

相关文章
相关标签/搜索