day12 Java基础——自增自减运算符,初识Math类
自增、自减
package operator;
public class Demo05 {
public static void main(String[] args) {
int a = 3;//a 的初始值
int b = a++;//执行完这行代码后,先给b复制,再自增1
//这里隐藏了 a = a + 1
System.out.println(a);
//这里隐藏了 a = a + 1
int c = ++a;//执行这行代码前,先自增1,再给c赋值
System.out.println(a);
System.out.println(a);
System.out.println(b);
System.out.println(b);
System.out.println(c);
System.out.println(c);
}
}
4
5
5
3
3
5
5
幂运算
package operator;
public class Demo06 {
public static void main(String[] args) {
//幂运算
double pow = Math.pow(2,3);//2的三次方
System.out.println(pow);
}
}
8.0
很多运算我们用一些工具类来操作

1万+

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



