&和&&都可以用作逻辑与的运算符,表示逻辑与(and),当运算符两边的表达式的结果都为true时,整个运算结果才为true,否则,只要有一方为false,则结果为false。
&&还具有短路的功能,即如果第一个表达式为false,则不再计算第二个表达式,
package com.audition.java;
public class Test1 {
/**
* @Title: main
* @Description:TODO(这里用一句话描述这个方法的作用)
* @param args 设定文件
* @date 2013-10-9 下午03:15:44
*/
public static void main(String[] args) {
oneChar(2);
twoChar(2);
}
public static void oneChar(int b){
int a =1;
if(b>2&&++a>1){
System.out.println("true");
}else{
System.out.println("a--oneChar-->:"+a);
}
}
public static void twoChar(int b){
int a =1;
if(b>2&++a>1){
System.out.println("true");
}else{
System.out.println("a--twoChar-->:"+a);
}
}
}
、结果
a--oneChar-->:1
a--twoChar-->:2
3163

被折叠的 条评论
为什么被折叠?



