1. Math類
|
方法名
|
説明
|
|
public static int abs(int a)
|
獲取參數a的絕對值:
|
|
public static double ceil(double a)
|
向上取整
|
|
public static double floor(double a)
|
向下取整
|
|
public static double pow(double a, double b)
|
獲取a的b次冪
|
|
public static long round(double a)
|
四捨五入取整
|
System.out.println("向上取整:"+Math.ceil(13.4)); //14.0
System.out.println("向上取整:"+Math.ceil(-11.8)); //-11.0
System.out.println("向下取整:"+Math.floor(15.9)); //15.0
System.out.println("向下取整:"+Math.floor(-12.6)); //-13.0
System.out.println("2的8次冪:" + Math.pow(2, 8));//256.0
System.out.println("四捨五入 = "+Math.round(12.1)); //12
System.out.println("四捨五入 = "+Math.round(12.8)); //13
System.out.println(Math.random()); //[0.0 , 1.0)
System.out.println((int)(Math.random()*10+1)); //[1,11)
2. System類
常用API方法:
public static native long currentTimeMillis();
public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
public static void exit(int status)
public static void setOut(Prin