数学工具
Math
代表数学,是一个工具类,里面提供的都是对数据进行操作的一些静态方法
public class Test { public static void main ( String [ ] args) { System . out. println ( Math . abs ( - 3.14 ) ) ; System . out. println ( Math . ceil ( 4.000001 ) ) ; System . out. println ( Math . ceil ( 4.0 ) ) ; System . out. println ( Math . floor ( 4.999999 ) ) ; System . out. println ( Math . ceil ( 4.0 ) ) ; System . out. println ( Math . round ( 3.4999 ) ) ; System . out. println ( Math . round ( 3.5001 ) ) ; System . out. println ( Math . max ( 10 , 20 ) ) ; System . out. println ( Math . min ( 10 , 20 ) ) ; System . out. println ( Math . pow ( 2 , 3 ) ) ; System . out. println ( Math . pow ( 3 , 2 ) ) ; System . out. println ( Math . random ( ) ) ; }
}
BigDecimal
import java. math. BigDecimal ;
import java. math. RoundingMode ; public class Test { public static void main ( String [ ] args) { double a = 0.1 ; double b = 0.2 ; System . out. println ( a + b) ;
BigDecimal objA = BigDecimal . valueOf ( a) ; BigDecimal objB = BigDecimal . valueOf ( b) ; BigDecimal objC = objA. add ( objB) ; System . out. println ( objC) ; BigDecimal objD = objA. subtract ( objB) ; System . out. println ( objD) ; BigDecimal objE = objA. multiply ( objB) ; System . out. println ( objE) ; BigDecimal objF = objA. divide ( objB, 2 , RoundingMode . HALF_DOWN ) ; System . out. println ( objF) ; double res = objF. doubleValue ( ) ; System . out. println ( res) ; }
}
系统工具
System
public class Test { public static void main ( String [ ] args) {
long time = System . currentTimeMillis ( ) ; System . out. println ( time) ; }
}
Runtime
代表程序所在的运行环境 Runtime 是一个单例类
import java. io. IOException ; public class Test { public static void main ( String [ ] args) throws IOException , InterruptedException { Runtime r = Runtime . getRuntime ( ) ;
System . out. println ( r. availableProcessors ( ) ) ; System . out. println ( r. totalMemory ( ) / 1024.0 / 1024.0 + "MB" ) ; System . out. println ( r. freeMemory ( ) / 1024.0 / 1024.0 + "MB" ) ; Process obj = r. exec ( "E:\\mine\\run.exe" ) ; Thread . sleep ( 5000 ) ; obj. destroy ( ) ; }
}