常用API大全

2021-10-19 14:18:02 字數 2174 閱讀 1608

2、math中方法的呼叫方式

3、math類的常用方法

方法名 方法名

說明public static int abs(int a)

返回引數的絕對值

public static double ceil(double a)

返回大於或等於引數的最小double值,等於乙個整數

public static double floor(double a)

返回小於或等於引數的最大double值,等於乙個整數

public static int round(float a)

按照四捨五入返回最接近引數的int

public static int max(int a,int b)

返回兩個int值中的較大值

public static int min(int a,int b)

返回兩個int值中的較小值

public static double pow (double a,double b)

返回a的b次冪的值

public static double random()

返回值為double的正值,[0.0,1.0)

public

class

systemdemo

// 獲取**執行結束後的時間節點

long end = system.

currenttimemillis()

; system.out.

println

("共耗時:"

+(end - start)

+"毫秒");

}}

檢視方法原始碼的方式

重寫tostring方法的方式

tostring方法的作用:

示例**:

class

student

extends

object

public

student

(string name,

int age)

public string getname()

public

void

setname

(string name)

public

intgetage()

public

void

setage

(int age)

@override

public string tostring()

';}}

public

class

objectdemo

}

執行結果:

student

student

重寫equals方法的場景

重寫equals方法的方式

示例**:

class

student

public

student

(string name,

int age)

public string getname()

public

void

setname

(string name)

public

intgetage()

public

void

setage

(int age)

@override

public

boolean

equals

(object o)

}public

class

objectdemo

}

面試題

// 看程式,分析結果

string s = 「abc」;

stringbuilder sb =

newstringbuilder

(「abc」);s.

equals

(sb)

; sb.

equals

(s);

public

class

interviewtest

}

陣列常用API

var color red green blue var color2 yellow black brown var color3 color.concat color2 concat 是將引數傳遞進來的陣列內容 拼接到呼叫者後面,不修改原陣列 var color4 color.tostring 陣...

陣列常用API

陣列常用api push 末尾新增 pop 末尾刪除 unshift 開頭新增 concat 開頭刪除 reserver 顛倒陣列 sort 排序 join 將陣列轉換成字串 splice 刪除 替換 插入 slice 切割陣列 indexof data,start 查詢關鍵字 es5新增 第乙個下...

常用API彙總

string 三角函式 方法名功能描述 引數返回值 sin num 正弦double double cos num 余弦double double tan num 正切double double 求整 絕對值 方法名功能描述 引數返回值 abs num 求絕對值 int long float dou...