有好心人幫我解釋一下每行代碼的含義嗎,謝謝!
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);
? ? ? ? }
}
}
2018-09-08
class Element ?? //創(chuàng)建一個類
{
? ? public int value; ? // 定義成員變量
? ? public Element next;? //定義成員變量
}
public class Program { ? // 創(chuàng)建一個program類
public static void main(String[] args) { ? //main函數(shù)
Element start=new Element(); ?? // 創(chuàng)建一個start的對象
start.value=22; ? //定義value的值
Element end=start; ? ?? // 創(chuàng)建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) {//遍歷數(shù)組
? ? ? ? ? ? System.out.println(temp.value);// 輸出
? ? ? ? }
}
}