JAVA中Math类的调用

// Math类中的方法
// Math.nextUp(a);//返回一个比a大一点点的浮点数
// System.out.println(Math.nextUp(2.5));
// Math.nextDown(a);返回一个比a稍微小一点点的数
// System.out.println(Math.nextDown(2.4));
//Math.nextAfter(a,b);返回一个a,b之间与a相邻的浮点数
// System.out.println(Math.nextAfter(1.5,26));
// Math.round(x);四舍五入,x为float时返回int型,x为double型时返回long型
// System.out.println(Math.round(-54.2));
// Math.rint(x); 四舍五入,返回double类型
// Math.random();取一个大于等于0同时小于等于1的随机数[0,1],若要取[0,n]之中的随机数,则只需Math.random()*n
//Math.floor();返回小的值,在x轴上向左靠
// System.out.println(Math.floor(-2.5));//-3.0
// Math.ceil();返回大的数,在x轴上向右靠
// Math.abs(x);求x的绝对值
// Math.max();
// Math.min();求最大最小值
// Math.pow(x,n);计算x的n次方
// Math.exp(x);计算e的x次方
// Math.hypot(x,y);计算(x的平方 + y的平方)的平方根
// Math.cbrt();计算立方根
// Math.sqrt();计算平方根

猜你喜欢

转载自blog.csdn.net/weixin_44895008/article/details/89739046