Java關係運算符示例
下麵的簡單示例程序演示了關係運算符。複製並粘貼到Test.java的文件中的以下Java程序編譯並運行這個程序:
public class Test { public static void main(String args[]) { int a = 10; int b = 20; System.out.println("a == b = " + (a == b) ); System.out.println("a != b = " + (a != b) ); System.out.println("a > b = " + (a > b) ); System.out.println("a < b = " + (a < b) ); System.out.println("b >= a = " + (b >= a) ); System.out.println("b <= a = " + (b <= a) ); } }
這將產生以下結果:
a == b = false a != b = true a > b = false a < b = true b >= a = true b <= a = false