Math工具类常用API使用案例
生活随笔
收集整理的這篇文章主要介紹了
Math工具类常用API使用案例
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
對(duì)基礎(chǔ)API的使用能夠熟練掌握,能極大提高開發(fā)效率。有些知識(shí)是很簡單,但并不是我們不學(xué)習(xí)和掌握它們的借口,越是簡單的東西,在關(guān)鍵時(shí)刻越是能起到至關(guān)重要的作用,就好比我們花很長時(shí)間解決的一個(gè)BUG,結(jié)果到頭來竟是少打了一個(gè);所致,是不是很惱火。
Math工具類常用API:
@Testpublic void testMathUtil(){//Math:包含了一些基本的數(shù)學(xué)運(yùn)算方法//static double PISystem.out.println("PI的值:"+Math.PI);//static double abs(double a) :返回絕對(duì)值System.out.println("返回絕對(duì)值:"+Math.abs(15));System.out.println("返回絕對(duì)值:"+Math.abs(-10));//static double ceil(double a) 天花板 向上取整System.out.println("向上取整:"+Math.ceil(1.2));System.out.println("向上取整:"+Math.ceil(1.6));//static double floor(double a) 地板 向下取整System.out.println("向下取整:"+Math.floor(1.2));System.out.println("向下取整:"+Math.floor(1.6));//static long round(double a) :四舍五入System.out.println("四舍五入:"+Math.round(1.2));System.out.println("四舍五入:"+Math.round(1.6));//static double max(double a, double b)System.out.println("比較3和4誰最大==> "+Math.max(3, 4));//static double pow(double a, double b) :返回第一個(gè)參數(shù)的第二個(gè)參數(shù)次冪System.out.println("返回第一個(gè)參數(shù)的第二個(gè)參數(shù)次冪==> "+Math.pow(3, 2));//static double random() :返回一個(gè)隨機(jī)數(shù),大于零且小于一System.out.println("返回一個(gè)隨機(jī)數(shù),大于零且小于一==> "+Math.random());String s = Math.random() + "";System.out.println("生成一個(gè)隨機(jī)數(shù)只保留2位小數(shù)==> "+s.substring(0, s.lastIndexOf(".") + 3));} 與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Math工具类常用API使用案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hexo搭建个人博客常用命令
- 下一篇: 自定义数组操作工具类代码示例