abs() :该方法给出了参数的绝对值,参数可以是int,float,long,double,short,byte
Syntax
double abs(double d)
float abs(float f)
int abs(int i)
long abs(long lng)
public class Test {
public static void main(String args[]) {
Integer a = -8;
double d = -100;
float f = -90;
System.out.println(Math.abs(a));
System.out.println(Math.abs(d));
System.out.println(Math.abs(f));
}
}
ceil():该方法给出大于或等于参数的最小整数
Syntax
double ceil(double d)
double ceil(float f)
public class Test {
public static void main(String args[]) {
double d = -100.675;
float f = -90;
System.out.println(Math.ceil(d));
System.out.println(Math.ceil(f));
System.out.println(Math.floor(d));
System.out.println(Math.floor(f));
}
}
floor() 该方法给出小于或等于参数的最大整数
Syntax
double floor(double d)
double floor(float f)
public class Test {
public static void main(String args[]) {
double d = -100.675;
float f = -90;
System.out.println(Math.floor(d));
System.out.println(Math.floor(f));
System.out.println(Math.ceil(d));
System.out.println(Math.ceil(f));
}
}
rint():返回值最接近参数的整数
Syntax
double rint(double d)
public class Test {
public static void main(String args[]) {
double d = 100.675;
double e = 100.500;
double f = 100.200;
System.out.println(Math.rint(d));
System.out.println(Math.rint(e));
System.out.println(Math.rint(f));
}
}
round():返回最接近的long或int
Syntax
This method has the following variants −
long round(double d)
int round(float f)
public class Test {
public static void main(String args[]) {
double d = 100.675;
double e = 100.500;
float f = 100;
float g = 90f;
System.out.println(Math.round(d));
System.out.println(Math.round(e));
System.out.println(Math.round(f));
System.out.println(Math.round(g));
}
}
min():给出两个参数的最小值,参数可以是int,float,long,double
Syntax
This method has the following variants −
double min(double arg1, double arg2)
float min(float arg1, float arg2)
int min(int arg1, int arg2)
long min(long arg1, long arg2)
public class Test {
public static void main(String args[]) {
System.out.println(Math.min(12.123, 12.456));
System.out.println(Math.min(23.12, 23.0));
}
}
max() 给出两个参数最大值,参数可以是int,float,long,double
Syntax
This method has the following variants −
double max(double arg1, double arg2)
float max(float arg1, float arg2)
int max(int arg1, int arg2)
long max(long arg1, long arg2)
public class Test {
public static void main(String args[]) {
System.out.println(Math.max(12.123, 12.456));
System.out.println(Math.max(23.12, 23.0));
}
}

pow():返回第一个参数基于第二参数次方的值
public class Test {
public static void main(String args[]) {
double x = 11.635;
double y = 2.76;
System.out.printf("The value of e is %.4f%n", Math.E);
System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));
}
}
Math.sqrt() 平方根
Math.sin()
Math.cos()
Math.tan()
....
Math.random() 产生一个0到1的随机数