确定 Java 中数组的长度(初学者)
Determining length in an array in Java (beginner)
我正在使用构造函数和数组,但我不明白为什么我无法确定此代码中的长度:
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.
我正在使用构造函数和数组,但我不明白为什么我无法确定此代码中的长度:
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.