class Student  {
public String ID; public String name; public int score; public Student() {
this.ID = "";
this.name = "";
this.score = 0;
}
                public String toString() {
return ID + " " + name + " " + String.valueOf(score);
}
          }public class C {
public static int row; public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
row = sc.nextInt();
LinkedList<Student> l = new LinkedList<Student>();
Student[] st = new Student[N+1] ;
for (int i = 0; i < N; i++) {
System.out.println(st[i]);//为什么都输出null呢?而不是  0呢?(0前面是2个空格)
}
}

解决方案 »

  1.   

    因为st[i]还没有初始化,还没有new
    只是给数组分配了空间而已
      

  2.   

    来迟了……
    分配空间了吗?应该仅仅是个声明吧!
    class Student {
    public String ID; public String name; public int score; public Student() {
    this.ID = "";
    this.name = "";
    this.score = 0;
    } public String toString() {
    return ID + " " + name + " " + String.valueOf(score);
    }
    }public class Test {
    public static int row; public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    row = sc.nextInt();
    //LinkedList<Student> l = new LinkedList<Student>();
    Student[] st = new Student[N + 1];  //仅仅起到声明作用。
    for (int i = 0; i < N; i++) {
    st[i] = new Student();       //需要初始化;
    System.out.println(st[i]);
    }
    }
      

  3.   

    关于数组,可以参考类似http://java.chinaitlab.com/base/525802.html的一类文章。
      

  4.   

    因为st[i]还没有初始化,还没有new 
    只是给数组分配了空间而已
      

  5.   

    首先什么都输出是因为你没有初始化数组,
    其次,你问为什么不输出0,而输出null
    是因为数组是Object,object数组初始化之前每个元素都为null,
    假如,你这么写 int[] ii = new int[5];
    System.out.println(ii[i]);
    输出的是0,因为这是基本类型!
    这就是object和基本类型的区别!
      

  6.   

    8楼分析的对,对于引用类型的实例默认是null,必须对其进行初始化
      

  7.   

    应该仅仅是个声明 没有初始化 当然是null