代码和注释如下:
public class blog1 {
public static void main(String[] args) {
//++ -- 自增 自减 也称一元运算符
int a = 3;
int b = a++; //执行完这行代码后,先给b赋值,再自增
//a=a+1
System.out.println(b);
//a++ a=a+1
int c = ++a; //执行完这行代码前,先自增,再给c赋值
System.out.println(a);
System.out.println(b);
System.out.println(c);
//幂运算2^3 2*2*2 =8 很多运算,我们需要使用一些工具类来操作!
double pow = Math.pow(2,3);
System.out.println(pow);
}
}
我的代码截图如下:
逻辑运算符
public class blog2 {public static void main(String[] args) {
// 与(and)=&& 或(or)=|| 非(取反)=!(&&)
boolean a = true;
boolean b = false;
System.out.println("a && b:"+(a&&b)); //逻辑与运算:两个变量都为真,结果才为ture
System.out.println("a || b:"+(a||b)); //逻辑与运算:两个变量有一个变量为真,则结果为ture
System.out.println("!(a && b):"+!(a&&b));//逻辑与运算:如果是真,则变为假,如果是假,则变为真
//短路运算 如果运算前面发生了错误,则不运算后面的代码。
int c = 5;
boolean d = (c<4)&&(c++<4);
System.out.println(d);
System.out.println(c);
}
}
代码截图如下:



