常用API
Math
abs
public class MathDemo1 {
public static void main(String[] args) {
//abs 获取参数绝对值
System.out.println(Math.abs(-88));
System.out.println(Math.abs(88));
System.out.println(Math.abs(-2147483647));
}
}
目前保持正常,但有一个小bug。
public class MathDemo1 {
public static void main(String[] args) {
//abs 获取参数绝对值
System.out.println(Math.abs(-88));
System.out.println(Math.abs(88));
System.out.println(Math.abs(-2147483648));
}
}
bug原因:int取值范围内没有2147483648
ceil(向上取整)
System.out.println(Math.ceil(12.34));
System.out.println(Math.ceil(12.54));
System.out.println(Math.ceil(-12.54));
System.out.println(Math.ceil(-12.34));
向上取整(进一法),向数轴的正方向进1
floor (向下取整)
System.out.println(Math.floor(12.34));
System.out.println(Math.floor(12.54));
System.out.println(Math.floor(-12.54));
System.out.println(Math.floor(-12.34));
向下取整(去尾法)
round 四舍五入
System.out.println(Math.round(12.34));
System.out.println(Math.round(12.54));
System.out.println(Math.round(-12.54));
System.out.println(Math.round(-12.34));
max/min获取两个数中的较大值或较小值
获取a的b次幂
开平方/开立方
两道算法题
判断一个数是否为质数
算水仙花数
System
从1970年1月1日 08:00:00开始算起
Runtime
object
object没有带参构造方法(没有成员变量)。
如果打印一个对象,想要看到属性值的话,那么就重写toString方法就可以了。在重写的方法中,把对象的属性值进行拼接。
如果没有重写equals方法,那么默认使用object中的方法进行比较,比较的是地址值是否相等。一般来说地址值对于我们意义不大,所以我们会重写,重写之后比较的就是对象内部的属性值了。
字符串中的equals方法先判断参数是否为字符串,如果是字符串,再比较内部的属性,但是如果参数不是字符串,直接返回false。
在StringBuilder中,没有重写equals方法,使用的是object中的。在object当中默认是使用==号比较两个对象的地址值。
BigInteger对象一旦创立,内部记录的值不能改变。