Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中确定数组长度(初学者)_Java_Arrays_String Length - Fatal编程技术网

在Java中确定数组长度(初学者)

在Java中确定数组长度(初学者),java,arrays,string-length,Java,Arrays,String Length,我正在使用构造函数和数组,但我不明白为什么我不能在这段代码中确定长度: 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/1

我正在使用构造函数和数组,但我不明白为什么我不能在这段代码中确定长度:

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.

你把length
pers.length
拼错了,而不是
pers.lenght
我现在觉得很愚蠢,我刚刚意识到。谢谢大家!