JPI中常使用的類介紹:
阿新 • • 發佈:2018-08-12
class 退出 其他 final color 字符串 simple out str
Math類:
java.lang包下的
final,不可被繼承,
其中的方法和屬性都是靜態的
其構造方法私有化了,其他類不可以使用構造方法。
向上取整:Math.ceil(double d);
向下取整:Math.floor(double d);
取較大值:Math.max(arg0,arg1);
四舍五入:Math.round(arg0);
System類:
System.in:默認鍵盤輸出流
System.out:默認輸出流
System.error:錯誤輸出流
退出java虛擬機:System.exit(0);根據慣例,非 0 的狀態碼表示異常終止
Arraycopy:將源數組拷貝到目標數組中。例如:
int[] src = {1,2,3,4,5}; int[] desc = new int[8]; System.arraycopy(src, 0, desc, 0, src.length);
BigInteger類:存儲更大的整數
BigDecimal類:更精確的存儲小數
Date類:
new Date(0):返回值是1970年1月1日8時的原因是中國在東八區,實際系統時間還是0分0秒
時間對象轉日期字符串:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH時mm分ss秒"); String nowTime = dateFormat.format(new Date());
日期字符串轉時間對象:
String strNow = "2018年08月12日 20時28分49秒"; Date nowDate = dateFormat.parse(strNow); System.out.println(nowDate);
JPI中常使用的類介紹: