Java數據處理之 Math類與Object類
Math類
代碼展示
public static void main(String[] args) {
int i1 = -10;
double d1 = -123;
double d2 = 3.4;
int i2 = Math.abs(i1);//返回絕對值
double d3 = Math.ceil(d2);//返回大於或等於參數的最小整數 4.0
double d4 = Math.floor(d2);//返回小於或等於參數的最大整數 3.0
int i3 = Math.max(i1, i2);//返回兩個參數的較大值
int i4 = Math.min(i1, i2);//返回兩個參數的較小值
double d5 = Math.random();//返回0.0和1.0之間的double類型的隨機數,包括0.0,但不包括1.0
long l1= Math.round(d2);//返回四捨五入的整數值(long)
System.out.println(Math.sin(0.5*Math.PI));
System.out.println(Math.cos(0.5*Math.PI));
System.out.println(Math.tan(0));
System.out.println(Math.exp(1));//返回自然對數的冪
System.out.println(Math.sqrt(9));//平方根函數 3.0
System.out.println(Math.pow(2,3));//冪運算 8.0
}
Math類小結
Object類
代碼展示
public static void main(String[] args) {
Object Obj1 = 123;
Object Obj2 = 123;
Object Obj3 = "12";
System.out.println(Obj1.equals(Obj2));//判斷兩個對象的內容是否相等
System.out.println(Obj1.hashCode()==Obj3.hashCode());//獲取散列碼,使用這個散列碼快速判斷兩個對象是否不相等
System.out.println(Obj1);
System.out.println(Obj1.toString());//toString方法,顯示對象內容時,會被系統自動調用
System.out.println(Obj1.getClass());//用來獲取對象的類型,主要用於反射技術的實現
}
Object類小結
總結
學習從點滴開始,學到的東西可能會忘記,記得點贊收藏哦
System.out.println("我選擇滑稽取寵");