java中你容易忘记的基础大盘点 |和||的区别

public class test_or {
    public static void main(String[] args) {
        int a = 10;
        boolean  b = true;
        int c = 10;
        boolean  d = false;

        if(b|(a++)>0){
            System.out.println(a+"今天天气真晴朗aaa");
        }else {
            System.out.println(a+"处处好风光bbb");
        }

        if(b||(c++)>0){
            System.out.println(c+"今天天气真晴朗ccc");
        }else {
            System.out.println(c+"处处好风光ddd");
        }
    }
}

执行效果

D:\download\tool\jdk\install\bin\java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53194,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath D:\download\tool\jdk\install\jre\lib\charsets.jar;D:\download\tool\jdk\install\jre\lib\deploy.jar;D:\download\tool\jdk\install\jre\lib\ext\access-bridge-64.jar;D:\download\tool\jdk\install\jre\lib\ext\cldrdata.jar;D:\download\tool\jdk\install\jre\lib\ext\dnsns.jar;D:\download\tool\jdk\install\jre\lib\ext\jaccess.jar;D:\download\tool\jdk\install\jre\lib\ext\jfxrt.jar;D:\download\tool\jdk\install\jre\lib\ext\localedata.jar;D:\download\tool\jdk\install\jre\lib\ext\nashorn.jar;D:\download\tool\jdk\install\jre\lib\ext\sunec.jar;D:\download\tool\jdk\install\jre\lib\ext\sunjce_provider.jar;D:\download\tool\jdk\install\jre\lib\ext\sunmscapi.jar;D:\download\tool\jdk\install\jre\lib\ext\sunpkcs11.jar;D:\download\tool\jdk\install\jre\lib\ext\zipfs.jar;D:\download\tool\jdk\install\jre\lib\javaws.jar;D:\download\tool\jdk\install\jre\lib\jce.jar;D:\download\tool\jdk\install\jre\lib\jfr.jar;D:\download\tool\jdk\install\jre\lib\jfxswt.jar;D:\download\tool\jdk\install\jre\lib\jsse.jar;D:\download\tool\jdk\install\jre\lib\management-agent.jar;D:\download\tool\jdk\install\jre\lib\plugin.jar;D:\download\tool\jdk\install\jre\lib\resources.jar;D:\download\tool\jdk\install\jre\lib\rt.jar;D:\pro_idea\demo\oh-my-email\oh-my-email-master\target\test-classes;D:\pro_idea\demo\oh-my-email\oh-my-email-master\target\classes;D:\download\tool\maven\repository\com\sun\mail\javax.mail\1.6.0\javax.mail-1.6.0.jar;D:\download\tool\maven\repository\javax\activation\activation\1.1\activation-1.1.jar;D:\download\tool\maven\repository\com\mitchellbosecke\pebble\2.2.0\pebble-2.2.0.jar;D:\download\tool\maven\repository\com\google\guava\guava\16.0.1\guava-16.0.1.jar;D:\download\tool\maven\repository\com\coverity\security\coverity-escapers\1.1\coverity-escapers-1.1.jar;D:\download\tool\maven\repository\org\slf4j\slf4j-api\1.6.1\slf4j-api-1.6.1.jar;D:\download\tool\maven\repository\com\github\subchen\jetbrick-template\2.1.2\jetbrick-template-2.1.2.jar;D:\download\tool\maven\repository\com\github\subchen\jetbrick-commons\2.1.1\jetbrick-commons-2.1.1.jar;D:\download\tool\maven\repository\org\antlr\antlr4-runtime\4.3\antlr4-runtime-4.3.jar;D:\download\tool\maven\repository\org\abego\treelayout\org.abego.treelayout.core\1.0.1\org.abego.treelayout.core-1.0.1.jar;D:\download\tool\maven\repository\org\antlr\antlr4-annotations\4.3\antlr4-annotations-4.3.jar;D:\download\tool\maven\repository\junit\junit\4.12\junit-4.12.jar;D:\download\tool\maven\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\download\tool\ide\idea\ideaIU-2016.3.1_install\lib\idea_rt.jar io.github.biezhi.ome.test_or
Connected to the target VM, address: '127.0.0.1:53194', transport: 'socket'
11今天天气真晴朗aaa
10今天天气真晴朗ccc
Disconnected from the target VM, address: '127.0.0.1:53194', transport: 'socket'

Process finished with exit code 0
总结:左面true 右面正常运行

      左面false 右面不在运行


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值