回顾
Object类
toString: 默认返回包名.类名@地址值,重写之后返回对象的内容
equals: 默认比较两个对象的地址值,重写之后比较对象的内容
Date类:
public Date(); 当前时间
public Date(long millis);距离基准时间millis毫秒后的那个时间
DateFormat类:
public SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
格式化: public String format(Date d);
解析: public Date parse(String time);
Calendar类:
获取:Calendar cc = Calendar.getInstance();
方法:
public int get(int field);
public void add(int field,int value);
public void set(int field,int value);
Math类:
Math的方法都是静态的
public static double abs(double d);
public static double ceil(double d);
public static double floor(double d);
public static long round(double d);
public static double pow(double d,double d);
System类:
System类的方法也是静态,并且不能创建对象(System的构造方法私有化了)
System.exit(0); 退出JVM
System.currentTimeMillis(); 获取当前时间的毫秒值
System.arrayCopy(源数组,开始索引,目标数组,开始索引,复制的元素个数);
主要内容:
BigInteger 大整数计算
BigDecimal 高精度计算
Arrays 工具类(方法都是静态的)
包装类(八种基本类型对应的引用类型)
String类的常用方法
(类,抽象类,接口,多态)
1.BigInteger的介绍
用于大整数计算(理论整数的位数是不受限制的)
public BigInteger(String num); //创建一个大整数
BigInteger不能直接使用+-*/进行计算,而是用通过方法进行计算
public BigInteger add(BigInteger value); 求和
public BigInteger subtract(BigInteger value); 求差
public BigInteger multiply(BigInteger value); 求积
public BigInteger divide(BigInteger value); 求商
public class TestBigInteger {
public static void main(String[] args) {
//1.创建一个BigInteger
BigInteger b1 = new BigInteger("99999999999");
//2.计算
//求和
BigInteger add = b1.add(new BigInteger("111111111111"));
System.out.println(add);
//求差
BigInteger subtract = b1.subtract(new BigInteger("222222222222"));
System.out.println(subtract);
//求积
BigInteger multiply = b1.multiply(new BigInteger("33333333"));
System.out.println(multiply);
//求商,如果除不尽,那么不要小数部分
b1 = new BigInteger("10");
BigInteger divide = b1.divide(new BigInteger("3"));
System.out.println(divide);
}
}
2.BigDecimal类
做高精度的浮点数运算
public BigDecimal(double d);
public BigDecimal(String s); 【推荐】
BigDecimal不能直接使用+-*/进行计算,而是用通过方法进行计算
public BigDecimal add(BigDecimal value) 加法运算
public BigDecimal subtract(BigDecimal value) 减法运算
public BigDecimal multiply(BigDecimal value) 乘法运算
public BigDecimal divide(BigDecimal value) 除法运算(能除尽)
public BigDecimal divide(BigDecimal value,int 保留位数,RoundingMode.HALP_UP) 除法运算(不能除尽)
public class TestBigDecimal02 {
public static void main(String[] args) {
//1.创建一个BigDecimal
BigDecimal b1 &#