當前位置:首頁 » 編程語言 » java輸出地址

java輸出地址

發布時間: 2024-06-12 06:55:17

java列印出地址值

第一個列印的是對象本身,列印出來的就是對象地址。

第二個列印的是方法調用,方法是有返回值的,列印出來的就是返回值。

對象地址是隨機分配的吧,都不會有特定的內存地址分配給你的,不信你可以new兩個相同的對象出來,在分別直接列印對象,這兩個地址肯定是不一樣的。



java是一門面向對象的編程語言:

java語言具有功能強大和簡單易用兩個特徵,具有簡單性、面向對象、分布式等特點,可以編寫桌面應用程序、Web應用程序、分布式系統和嵌入式系統應用程序等。

㈡ Java輸出對象的數組是地址,如何輸出其值

可以重寫Student類中的toString()方法,以下例子僅作為參考:

classStudent
{
//該類的實例變數
publicStringno;
publicStringname;
publicStringsex;
publicintyuwen;
publicintshuxue;
publicintyingyu;
publicintlizong;

//創建構造器
publicStudent(Stringno,Stringname,Stringsex,intyuwen,intshuxue,intyingyu,intlizong){
this.no=no;
this.name=name;
this.sex=sex;
this.yuwen=yuwen;
this.shuxue=shuxue;
this.yingyu=yingyu;
this.lizong=lizong;
}

//重寫toString()方法,該方法輸出對象
publicStringtoString(){
return"Student[no:"+no+",name:"+name+",sex:"+sex+",yuwen:"+yuwen+",shuxue:"+shuxue+",yingyu:"+yingyu+",lizong:"+lizong+"]";
}
}
publicclassStudent1
{
publicstaticvoidmain(String[]args)
{
Studentstu1=newStudent("001","Zhang","男",65,70,53,80);
Studentstu2=newStudent("002","Cheng","女",75,75,85,78);
Studentstu3=newStudent("003","Li","女",68,45,95,72);
Studentstu4=newStudent("004","Cha","男",67,70,64,62);
Studentstu5=newStudent("005","Xun","男",65,90,78,85);
Student[]st={stu1,stu2,stu3,stu4,stu5};
for(Studentc:st){
System.out.println(c);
}
}
}

㈢ 奼俲ava紼嬪簭錛氱敤閿鐩樺悜鎺у埗鍙拌緭鍏ヤ竴涓狤-mail鍦板潃錛屽垎鏋愯ュ湴鍧鑾峰彇騫惰緭鍑哄煙鍚嶅傦細鈥126.co

import java.util.Scanner;
public class EmailAnalyzer {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 鎻愮ず鐢ㄦ埛杈撳叆E-mail鍦板潃
System.out.print("璇瘋緭鍏E-mail鍦板潃錛");
String email = scanner.nextLine();
// 鑾峰彇鍩熷悕
int indexOfAtSign = email.indexOf('@');
String domain = email.substring(indexOfAtSign + 1);
// 杈撳嚭鍩熷悕
System.out.println("鍩熷悕錛" + domain);
}
}

㈣ java鎬庝箞杈撳嚭鐨勬槸鍦板潃涓嶆槸鏁版嵁錛

浣犺緭鍑虹殑鏄鏁扮粍鐨勫紩鐢 a 灝辨槸鏁扮粍鍦ㄥ爢鍐呭瓨涓鐨勫紩鐢,褰撶劧鏄鍦板潃鍊間簡

浣犺佹槸鎯寵緭鍑烘帓搴忓悗鐨勬暟緇勫彲浠ヨ繖涔堝仛:
for(int s:a){
System.out.print(s+"\t");

}

㈤ java 增強for循環為什麼輸出的是一串地址值

為什麼java增強for循環輸出一串地址值?

因為for(String str: array)java的增強for循環左邊有一個參數類型,右邊有一個循環數組,嚴格來說兩個數組之間沒有聯系,除非一個數組的值與另一個數組的下標有關。前端增強型for循環可以同時輸出兩個數組。for(var index in array)因為前端增強for的左邊是數組的下標,右邊是循環數組,只要加上循環長度大的數組和一些判斷,就可以同時輸出兩個數組。以上是我個人的看法,希望對你有幫助。

熱點內容
計算機上輸入ftp還是htp 發布:2025-09-16 06:00:09 瀏覽:549
汽車裡面的花瓶怎麼配置 發布:2025-09-16 05:56:05 瀏覽:449
溯源碼貼 發布:2025-09-16 05:52:56 瀏覽:148
檢測信號數據存儲 發布:2025-09-16 05:21:41 瀏覽:404
androiddagger2 發布:2025-09-16 04:38:38 瀏覽:123
javahttp編程 發布:2025-09-16 04:33:44 瀏覽:303
壓縮安裝器 發布:2025-09-16 03:47:17 瀏覽:181
特產網源碼 發布:2025-09-16 03:42:24 瀏覽:331
安卓faceplay怎麼付款 發布:2025-09-16 03:32:34 瀏覽:588
安卓rom包里有什麼 發布:2025-09-16 03:07:57 瀏覽:356