shortcircuit.java
来自「java编程思想是一本非常经典的书籍 此源码包涵了书籍的所有源码 书籍源码」· Java 代码 · 共 39 行
JAVA
39 行
//: c03:ShortCircuit.java
// Demonstrates short-circuiting behavior.
// with logical operators.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import com.bruceeckel.simpletest.*;
public class ShortCircuit {
static Test monitor = new Test();
static boolean test1(int val) {
System.out.println("test1(" + val + ")");
System.out.println("result: " + (val < 1));
return val < 1;
}
static boolean test2(int val) {
System.out.println("test2(" + val + ")");
System.out.println("result: " + (val < 2));
return val < 2;
}
static boolean test3(int val) {
System.out.println("test3(" + val + ")");
System.out.println("result: " + (val < 3));
return val < 3;
}
public static void main(String[] args) {
if(test1(0) && test2(2) && test3(2))
System.out.println("expression is true");
else
System.out.println("expression is false");
monitor.expect(new String[] {
"test1(0)",
"result: true",
"test2(2)",
"result: false",
"expression is false"
});
}
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?