public class test_and {
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(d&&(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:52670,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_and
Connected to the target VM, address: '127.0.0.1:52670', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:52670', transport: 'socket'
11今天天气真晴朗aaa
10处处好风光ddd
Process finished with exit code 0
总结:& 无论左面是true还是false 右面都会执行
&& 只要左面是false 右面就不执行了