public static void main(String[] args){
ListNode node1 = new ListNode(4);
ListNode node2 = new ListNode(5);
ListNode node3 = new ListNode(2);
ListNode node4 = new ListNode(21);
ListNode node5 = new ListNode(43);
ListNode node6 = new ListNode(52);
ListNode node7 = new ListNode(12);
}
我想使用'顺序声明变量。或者'而' JAVA中的语法。
在C中,我知道有一种方法可以使用MACRO
顺序声明变量但是,在java中,我该怎么做?
答案 0 :(得分:2)
您可以使用array of Objects
for loop
ListNode[] node = new ListNode[7];
for(int i = 0; i<7; i++) {
//scan a value you want to pass
node[i] = new ListNode(valueyouwanttopass);
}
或使用while loop
,如下所示:
ListNode[] node = new ListNode[7];
int i = 0;
while(i<7) {
//scan a value you want to pass
node[i] = new ListNode(valueyouwanttopass);
i++;
}