亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

有好心人幫我解釋一下每行代碼的含義嗎,謝謝!

class Element

{

? ? public int value;

? ? public Element next;

}



public class Program {

public static void main(String[] args) {

Element start=new Element();

start.value=22;?

Element end=start;

Element temp=start;

end.next=null;

temp=new Element();

temp.value=45;

end.next=temp;

end=end.next;

end.next=null;

//printing, simple way

? ? ? ? System.out.println(start.value);

? ? ? ? System.out.println(start.next.value);

? ? ? ??

? ? ? //printing, universal way

? ? ? ? for (temp = start; temp != null; temp = temp.next) {

? ? ? ? ? ? System.out.println(temp.value);

? ? ? ? }


}


}


正在回答

1 回答

class Element ?? //創建一個類

{

? ? public int value; ? // 定義成員變量

? ? public Element next;? //定義成員變量

}



public class Program { ? // 創建一個program類

public static void main(String[] args) { ? //main函數

Element start=new Element(); ?? // 創建一個start的對象

start.value=22; ? //定義value的值

Element end=start; ? ?? // 創建element的對象?

Element temp=start;? //同上

end.next=null; ? // 給next賦值為null,既為空

temp=new Element();// 實例化一個對象

temp.value=45;? // 賦值

end.next=temp; //同上

end=end.next;//同上

end.next=null;//同上

//printing, simple way

? ? ? ? System.out.println(start.value); ? ? //輸出語句

? ? ? ? System.out.println(start.next.value); //輸出

? ? ? ??

? ? ? //printing, universal way

? ? ? ? for (temp = start; temp != null; temp = temp.next) {//遍歷數組

? ? ? ? ? ? System.out.println(temp.value);// 輸出

? ? ? ? }


}


}


2 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

有好心人幫我解釋一下每行代碼的含義嗎,謝謝!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號