邏輯運算符

package com58.bj.java;

public class LuoJiDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		boolean a,b,c;
		a = true;
		b = false;
		//邏輯與
		c = a & b;
		System.out.println(c); // false
		//邏輯或
		c = a | b;
		System.out.println(c);//true
		// 邏輯異或
		c = a ^ b;
		System.out.println(c); //true
		// 邏輯非
		c = ! a;
		System.out.println(c);//false
		// 短路與
		c = a && b;
		System.out.println(c);//false
		// 短路或
		c = a || b; 
		System.out.println(c);//true
		
		int i = 1, j = 2;
		boolean flag1 = (i > 3) && ((i+j)>5);
		System.out.println(flag1);
		boolean flag2 = (i <2) || ((i+j)<6);
		System.out.println(flag2);
		
	}

}
相關文章
相關標籤/搜索