JAVA常见方法(Number类)2

(1)min()

返回两个参数中的最小值。

double min(double arg1, double arg2);
float min(float arg1, float arg2);
int min(int arg1, int arg2);
long min(long arg1, long arg2);
    System.out.println(Math.min(12.123, 12.456));      
    System.out.println(Math.min(23.12, 23.0));

(2)max()

返回两个参数中的最大值。

double max(double arg1, double arg2);
float max(float arg1, float arg2);
int max(int arg1, int arg2);
long max(long arg1, long arg2);
        System.out.println(Math.max(12.123, 18.456));      
        System.out.println(Math.max(23.12, 23.0)); 

(3)pow()

pow() 方法用于返回第一个参数的第二个参数次方。

double pow(double base, double exponent);
System.out.printf("pow(%.3f, %.3f) 为 %.3f%n", x, y, Math.pow(x, y));

(4)sqrt()

sqrt() 方法用于返回参数的算术平方根

double sqrt(double d);
System.out.printf("sqrt(%.3f) 为 %.3f%n", x, Math.sqrt(x));

(5)random()

random() 方法用于返回一个随机数,随机数范围为 0.0 =< Math.random < 1.0。

static double random();
System.out.println( Math.random() );

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值