number java_java中Number Math 类方法
package NumberAndMath;
/**
* Number and Math 方法
* @author Administrator
*
*/
public class NumAndMathDome {
public static void main(String[] args) {
/**
* xxxValue
* 將 Number 對象轉(zhuǎn)換為xxx數(shù)據(jù)類型的值并返回
*/
Integer x =10;
System.out.println("x is byte:"+x.byteValue());
System.out.println("x is double:"+x.doubleValue());
System.out.println("x is shor:"+x.shortValue());
System.out.println("x is long:"+x.longValue());
System.out.println("x is float:"+x.floatValue());
/**
* compareTo
* number類與參數(shù)做比較,若比較相等返回0,大于返回1,小于返回-1
*/
Integer x =15;
System.out.println(x.compareTo(17));
System.out.println(x.compareTo(15));
System.out.println(x.compareTo(10));
/**
* equals()
* 判斷number對象是否與參數(shù)相等,相等則返回ture,否則false
*/
Integer x =44;
Integer y =20;
Integer z =44;
System.out.println(x.equals(y));
System.out.println(x.equals(z));
/**
* round() 方法返回一個最接近的int、long型值
*/
double a =101.568;
double b = 200.4;
float c = 83f;
System.out.println(Math.round(a));//返回值為102
System.out.println(Math.round(b));//返回值為200
System.out.println(Math.round(c));//返回值為83
/**
* math.max() math.min() 返回最大值和最小值
*/
System.out.println(Math.max(23, 44));
System.out.println(Math.min(44, 3));
}
/**
* random()隨機數(shù),不接受任何參數(shù)
*/
System.out.println(Math.random());
}
}
}
總結(jié)
以上是生活随笔為你收集整理的number java_java中Number Math 类方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《信息学奥赛一本通提高篇》第6章 组合数
- 下一篇: 如何在data visualizatio