java-number2
生活随笔
收集整理的這篇文章主要介紹了
java-number2
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
abs() :該方法給出了參數(shù)的絕對值,參數(shù)可以是int,float,long,double,short,byte
Syntax double abs(double d) float abs(float f) int abs(int i) long abs(long lng)public class Test { public static void main(String args[]) {Integer a = -8;double d = -100;float f = -90;System.out.println(Math.abs(a));System.out.println(Math.abs(d)); System.out.println(Math.abs(f)); } }ceil():該方法給出大于或等于參數(shù)的最小整數(shù)
Syntax double ceil(double d) double ceil(float f)public class Test { public static void main(String args[]) {double d = -100.675;float f = -90; System.out.println(Math.ceil(d));System.out.println(Math.ceil(f)); System.out.println(Math.floor(d));System.out.println(Math.floor(f)); } }floor() 該方法給出小于或等于參數(shù)的最大整數(shù)
Syntax double floor(double d) double floor(float f)public class Test { public static void main(String args[]) {double d = -100.675;float f = -90;System.out.println(Math.floor(d));System.out.println(Math.floor(f)); System.out.println(Math.ceil(d));System.out.println(Math.ceil(f));} }rint():返回值最接近參數(shù)的整數(shù)
Syntax double rint(double d)public class Test {public static void main(String args[]) {double d = 100.675;double e = 100.500;double f = 100.200;System.out.println(Math.rint(d));System.out.println(Math.rint(e)); System.out.println(Math.rint(f)); } }round():返回最接近的long或int
Syntax This method has the following variants ?long round(double d) int round(float f)public class Test { public static void main(String args[]) {double d = 100.675;double e = 100.500;float f = 100;float g = 90f;System.out.println(Math.round(d));System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); } }min():給出兩個參數(shù)的最小值,參數(shù)可以是int,float,long,double
Syntax This method has the following variants ?double min(double arg1, double arg2) float min(float arg1, float arg2) int min(int arg1, int arg2) long min(long arg1, long arg2)public class Test {public static void main(String args[]) {System.out.println(Math.min(12.123, 12.456)); System.out.println(Math.min(23.12, 23.0)); } }max() 給出兩個參數(shù)最大值,參數(shù)可以是int,float,long,double
Syntax This method has the following variants ?double max(double arg1, double arg2) float max(float arg1, float arg2) int max(int arg1, int arg2) long max(long arg1, long arg2)public class Test { public static void main(String args[]) {System.out.println(Math.max(12.123, 12.456)); System.out.println(Math.max(23.12, 23.0)); } } pow():返回第一個參數(shù)基于第二參數(shù)次方的值
public class Test { public static void main(String args[]) {double x = 11.635;double y = 2.76;System.out.printf("The value of e is %.4f%n", Math.E);System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));} }Math.sqrt() 平方根
Math.sin()
Math.cos()
Math.tan()
....
Math.random() 產(chǎn)生一個0到1的隨機(jī)數(shù)
轉(zhuǎn)載于:https://www.cnblogs.com/cyany/p/9147964.html
總結(jié)
以上是生活随笔為你收集整理的java-number2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java应用:csv文件的读写
- 下一篇: 安装consul