java中有一个Math类里面很多静态的方法,都是一些常见的数学公式的实现,例如求平方根的Math.sqrt(n),求a的b次方Math.pow(a, b),求绝对值Math.abs(n)等很多。下面是一些演示。
public class MathTest
{
public static void main(String[] args)
{
int n = 16;
System.out.println(Math.sqrt(n));
System.out.println(Math.pow(2, 3));
System.out.println(Math.abs(-4));
System.out.println(Math.log10(100));
}
}