static(靜態(tài))關(guān)鍵字
既可以修飾成員方法也可以修飾成員變量
代碼塊
Java API定義的靜態(tài)類為工具類谬擦,將構(gòu)造方法私有化延欠,無法聲明對象峡竣,無法訪問類中的內(nèi)容和成員现恼、成員變量沒有關(guān)系愧捕。
Math.ceil(1.2)//2.0 天花板 向上取整
Math.floor(1.2)//1.0 地板 向下取整
static long round(double a)//四舍五入
Math.round(1.2)\\1
Math.round(1.6)\\2 返回的數(shù)值為整型
Math.random()//返回一個(gè)隨機(jī)數(shù)奢驯,大于0小于1
自定義工具類
public class MyArrays{
? private MyArrays(){}
? public static int getMax(int[] arr){
? ? int max = 0;
? ? for(int x? = 0; x<arr.length;x++){
? ? ? ? if(arr[x] > max){
? ? ? ? ? ? max = arr[x];
? ? ? ? ? }
? ? ? }?
? ? return max;
? }
}