Method Description Example abs( x bsolute value of x abs(23.7)is23.7 (this method also has versions for float, abs( 0.0 )is 0.0 nt and long values) abs(-23.7)is23.7 eil( x )rounds x to the smallest integer not less than ceil( 9.2 )is 10.0 a1(-9.8)1s-9.0 cos( x trigonometric cosine ofx cos(0.0)1s1.0 is in radians) exp( x ) exponential method ex e(1.0)is2.71828 ex(20)is738906 floor( x)rounds x to the largest integer not greater floor( 9.2 )is90 than x £1oor(-9.8)1s-10.0 log( x) natural logarithm ofx(base e) 1og(2.718282)is1.0 1og(7389056)is2.0 larger value of x andy max(2.3,12.7)is12.7 y ( this method also has versions for float, max(-2.3, -12.7 )is-2.3 int and long values mn smaller value of x andy min(2.3,12.7)1s2.3 y (this method also has versions for float, min(-2.3,-12.7)is-12.7 nt and long values p。w(x, raised to power y(xy) pow(2.0,7.0)is128.0 y (9.0,.5)1s3.0 sin( x trigonometric sine of x sin(0.0 )is 0.0 (r is in radians) sqrt(x)square root of x sqrt(900.0)is30.0 sqxt(9.0)1s3.0 tan( x) trigonometric tangent of (x is in radians) tan(0.0)is0.0 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 6
方法的定义 ●自定义各种方法:这是程序员在结构化编程时的 主要工作。 ●在面向对象的时代,程序员除了要编写函数,更 主要的精力则放在如何将这些函数合理地分配、 包装成类 ●从JDK提供的数学方法类Mat我们可以知道,将 方法放入类中,并将其定义为静态( static)的是面 向对象软件提供公共方法( public method)的基 本作法。 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 7 方法的定义 ⚫ 自定义各种方法:这是程序员在结构化编程时的 主要工作。 ⚫ 在面向对象的时代,程序员除了要编写函数,更 主要的精力则放在如何将这些函数合理地分配、 包装成类 ⚫ 从JDK提供的数学方法类Math我们可以知道,将 方法放入类中,并将其定义为静态(static)的是面 向对象软件提供公共方法(public method)的基 本作法