
public class a5 {
public static void main(String[] args) {
int a = 100;
int b = a++;
int c = ++a;
System.out.println(a);
System.out.println(b);
System.out.println(c);
double pow = Math.pow(3,2);
System.out.println(pow);
}
}
public class a6 {
public static void main(String[] args) {
// 与(and ) 或(or) 非(取反)
boolean a = true;
boolean b = false;
System.out.println("a&&b:"+(a&&b)); //逻辑与运算:两个变量都为真,结果才为true
System.out.println("a|| b:"+(a||b)); //逻辑或运算:两个变量都为假,结果才为false
System.out.println("!(a|| b):"+!(a||b)); //非运算:如果为真,则变为假,如果为假则变为真
/* a&&b:false
a|| b:true
!(a|| b):false
Process finished with exit code 0
*/
}
}
public class a7 {
public static void main(String[] args) {
/*
a = 0011 1100
b = 0000 1101
---------------------------------
0 为 假, 1 为真
a & b = 0000 1100 与:a,b都为真才为真, 即a,b都为1,才为真
a | b = 0011 1101 或:a,b都为假才为假, 即a,b都为0,才为假
a ^ b = 0011 0001 异或:相同为0,不同为1
~b = 1111 0010 非:0——》1, 1--》0
-----------------------------------------
位运算:效率极高
<< *2;
>> /2;
0000 0000 0
0000 0001 1
0000 0010 2
0000 0011 3
0000 0100 4
0000 0101 5
0000 0110 6
0000 1000 8
0001 0000 16
*/
}
}
public class a8 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a +=b; //a=a+b;
a -=b; //a=a-b;
System.out.println(a);
//字符串连接符 +, String
System.out.println(""+a+b); //字符串在前,a+b 为拼接起来:1020
System.out.println(a+b+""); //字符串在后,a+b 输出前面的a+b的值
/*
10
1020
30
*/
}
}
public class a9 {
//三元运算符
public static void main(String[] args) {
// x ? y : z
// 如果为true,则结果为y,否则为z
int score = 30;
String sc = score < 60 ? "不及格" :"及格";
System.out.println(sc);
}
}
原文:https://www.cnblogs.com/chengmengdui/p/14725694.html