課程
/后端開(kāi)發(fā)
/Java
/Java入門(mén)第二季 升級(jí)版
equals有變量數(shù)量限制嗎?我同時(shí)設(shè)置了三個(gè)變量進(jìn)行比較,這是不是最終比較不同的原因?
2020-08-18
源自:Java入門(mén)第二季 升級(jí)版 9-9
正在回答
public?class?Telphone?{ ????float?screen; ????float?cpu; ????float?mem;//屬性 ????@Override ????public?boolean?equals(Object?o)?{ ????????if?(this?==?o)?return?true; ????????if?(o?==?null?||?getClass()?!=?o.getClass())?return?false; ????????Telphone?telphone?=?(Telphone)?o; ????????return?Float.compare(telphone.screen,?screen)?==?0?&& ????????????????Float.compare(telphone.cpu,?cpu)?==?0?&& ????????????????Float.compare(telphone.mem,?mem)?==?0;//自動(dòng)生成的Object?判斷工具 ????} }
public?class?Initail?{ ????public?static?void?main(String[]?args)?{ ????????Telphone?telphone1=new?Telphone(); ????????telphone1.?screen=1f; ????????telphone1.?cpu=2f; ????????telphone1.mem=3f;//telphone1賦值 ????????Telphone?telphone2=new?Telphone(); ????????telphone2.screen=1f; ????????telphone2.cpu=2f; ????????telphone2.mem=3f;//telphone2賦值 ????????if(telphone1.equals(telphone2)){ ????????????System.out.println("兩個(gè)手機(jī)是相同的!"); ????????} ????????else{ ????????????System.out.println("兩個(gè)手機(jī)是不同的"); ????????}//判斷 ????} }
沒(méi)有限制
三個(gè)分別比較,都相同則相同
舉報(bào)
課程升級(jí)!以終為始告別枯燥,在開(kāi)發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙
9 回答在手機(jī)上有沒(méi)有可以編寫(xiě)和運(yùn)行Java的程序嗎
3 回答我想問(wèn)下這個(gè)項(xiàng)目有誰(shuí)做出來(lái)了嗎?
3 回答有沒(méi)有人做了這個(gè)題目呢?
4 回答做出來(lái)了哈
4 回答請(qǐng)問(wèn)1-2的課程的程序能運(yùn)行嗎
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-10-20
2020-08-21
沒(méi)有限制
三個(gè)分別比較,都相同則相同