Java常用API類之Math System tostring用法詳解
1.注意(類名不能與math重名,否則可能報(bào)錯(cuò)誤)
1.math:可以直接拿來(lái)用的接口類
Math.abs(-90);返回參數(shù)的絕對(duì)值
Math.max(60,98)返回參數(shù)的最大值
Math.random()*100隨機(jī)函數(shù):隨機(jī)輸出一個(gè)數(shù)
等等
public static void main(String[] args){
int a = 1300, b = 1000;
System.out.println(Math.abs(-90));
System.out.println(Math.max(60,98));
System.out.println(Math.random()*100);
System.out.println(Math.ceil(b));
}}
結(jié)果:


2.System的API:
System.exit(0);// 在這個(gè)API下的往下內(nèi)容java代碼會(huì)停止執(zhí)行
System.currentTimeMillis();//返回與從1970年到現(xiàn)在的毫秒數(shù)
public class tyue {
public static void main(String[] args){
System.out.println("開(kāi)始!");
//System.exit(0);
System.out.println("結(jié)束!");
System.out.println(System.currentTimeMillis()*1/1000/60/60/24/365+"年");
Long begin=System.currentTimeMillis();
for(int i=0;i<=1000;i++)
{
System.out.println(i);
}
Long end=System.currentTimeMillis();
System.out.println("共耗時(shí)"+(end-begin)+"多少毫秒");
}}


3.object類中的:tostring()方法
如果:直接怎么寫:
zi sc=new zi();
System.out.println(sc);
System.out.println(sc.toString());
打印出:zi@1b6d3586;這樣不易觀察
可以通過(guò):
println
Ctrl+B: 打開(kāi)方法的聲明處點(diǎn)擊print(這個(gè)System.out.println(sc))
可以看到:
public class zi extends Object{
int a=30;
String we="我是說(shuō)";
public void show(){
System.out.println("我是說(shuō)");
}
}
public static void main(String[] args){
zi sc=new zi();
System.out.println(sc);
System.out.println(sc.toString());
//public void println(Object x) {
// String s = String.valueOf(x);
// synchronized (this) {
// print(s);
// newLine();
// }
// } //方法的聲明處 ctrl+b
/*public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
*/
sc.show();
}

可以: Alt+insert(插入鍵(Insert key,縮寫INS)是電腦鍵盤的一個(gè)鍵)

選擇toString()

然后全選確認(rèn),自動(dòng)生成

就Ok了
public class zi extends Object{
int a=30;
String we="我是說(shuō)";
@Override
public String toString() {
return "zi{" +
"a=" + a +
", we='" + we + '\'' +
'}';
}
public void show(){
System.out.println("我是說(shuō)");
}
}
重新編譯:得到
zi{a=30, we=‘我是說(shuō)'} //明顯

到此這篇關(guān)于Java常用API類之Math System tostring用法詳解的文章就介紹到這了,更多相關(guān)Java 常用API類內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java實(shí)現(xiàn)ATM系統(tǒng)超全面步驟解讀建議收藏
這篇文章主要為大家詳細(xì)介紹了用Java實(shí)現(xiàn)簡(jiǎn)單ATM機(jī)功能,文中實(shí)現(xiàn)流程寫的非常清晰全面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
Spring?Cloud?Alibaba微服務(wù)組件Sentinel實(shí)現(xiàn)熔斷限流
這篇文章主要為大家介紹了Spring?Cloud?Alibaba微服務(wù)組件Sentinel實(shí)現(xiàn)熔斷限流過(guò)程示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Java實(shí)現(xiàn)常見(jiàn)的排序算法的示例代碼
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)常見(jiàn)的排序算法(選擇排序、插入排序、希爾排序等)的相關(guān)資料,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-10-10
Mybatis?MappedStatement類核心原理詳解
這篇文章主要介紹了Mybatis?MappedStatement類,mybatis的mapper文件最終會(huì)被解析器,解析成MappedStatement,其中insert|update|delete|select每一個(gè)標(biāo)簽分別對(duì)應(yīng)一個(gè)MappedStatement2022-11-11
JAVA中數(shù)組插入與刪除指定元素的實(shí)例代碼
下面小編就為大家分享一篇JAVA中數(shù)組插入與刪除指定元素的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
Spring之動(dòng)態(tài)注冊(cè)bean的實(shí)現(xiàn)方法
這篇文章主要介紹了Spring之動(dòng)態(tài)注冊(cè)bean的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
java中調(diào)用GDAL DLL的實(shí)現(xiàn)方法
本篇文章是對(duì)java中調(diào)用GDAL DLL的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05

