运算符
-
与(and)、或(or)、非(no)
package operator;
public class Dome5 {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
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:"+(b&&a));
System.out.println("---------------------------------------------------------------------------------------------------------------");
int c = 5;
boolean d = (c++>4)&&(c<4);
boolean e = (c<4)&&(c++>4);//前面就是false的话,后面就不会输出
System.out.println(c);
System.out.println(d);
System.out.println(e);
}
}
位运算符
package operator;
public class Dome6 {
public static void main(String[] args) {
/* a=0011 1100
b=0000 1101
a&b=0000 1100
a|b=0011 0001
a^b=0011 0001
~b=1111 0010
<< 相当于*2
>> 相当于/2
0000 0000 = 0
0000 0001 = 1
0000 0010 = 2
0000 0011 = 3
0000 0100 = 4
0000 1000 = 8
*/
System.out.println(2<<3);
System.out.println(16>>3);
int a = 2;
int b = 8;
System.out.println(a*b);
}
}
package operator;
public class Dome7 {
public static void main(String[] args) {
//x?y:z ?:
//if x==true,结果为y,否则为z
int a = 61;
String type = a <60 ?"不及格":"及格";
System.out.println(type);
}
}