【发布时间】:2015-04-20 21:49:29
【问题描述】:
我正在使用构造函数和数组,但我不明白为什么我无法确定这段代码中的长度:
public class tests3 {
public static void main (String[] args){
Person[] pers = { new Person("10/05/1995", 5),
new Person("15/02/1993", 2),
new Person("20/11/1999"),
new Person("25/02/1980", 8),
new Person("30/01/1996", 3)
};
int nbElem = pers.lenght;
System.out.printf("%d", nbElem);
}
}
【问题讨论】:
-
你拼错了长度
-
pers.length而不是pers.lenght -
我现在觉得自己好蠢,我才意识到。谢谢大家!
标签: java arrays string-length