JAVA问题总结之7--Pow、sin、sqrt、abs等常用数学函数调用

来源:互联网 发布:数据解放生产力 编辑:程序博客网 时间:2024/06/07 02:35

JAVA问题总结之7--Pow、sin、sqrt、abs等常用数学函数调用


常用的使用方法:

Math.sin(0)//返回0.0,这是double类型的值Math.cos(0)//返回1.0 Math.tan(0.5)//返回0.5463024898437905 Math.round(6.6)//返回7 Math.round(6.3)//返回6 Math.ceil(9.2)//返回10 .0Math.ceil(-9.8)//返回-9 .0Math.floor(9.2)//返回9 .0Math.floor(-9.8)//返回-10 .0Math.sqrt(144)//返回12.0 Math.pow(5,2)//返回25.0 Math.exp(2)//返回7.38905609893065 Math.log(7.38905609893065)//返回2.0 Math.max(560, 289)//返回560 Math.min(560, 289)//返回289 Math.random()//返回0.0到1.0之间双精度的一个随机数值

实践代码:

package p1;public class test6 {   public static void main(String[] args){    System.out.println(Math.pow(10,155));    System.out.println(Math.sin(1));    System.out.println(Math.sin(Math.PI/4));    System.out.println(Math.abs(-90));    System.out.println(Math.sqrt(144));    for (int i=1;i<=20;i++){     System.out.println(i+":"+Math.random());        }   }}

结果:

1.0E1550.84147098480789650.70710678118654759012.01:0.052602674319820912:0.63390339987663573:0.490121398219262044:0.67665364958505715:0.452680378374327846:0.36847437948493397:0.089806388964083668:0.75232277124813889:0.2335541732600121510:0.4157945027763645411:0.933021479475095112:0.1047609102834388113:0.537291034986901614:0.488394965772936515:0.573854739622006716:0.977939954482812517:0.694664607563685118:0.364462371504694619:0.559370791830145620:0.15426893317772905

其他使用类推。

0 0