我接受了用户的输入并将其存储在变量“n”中。但是,当我尝试执行此代码时,我得到java.lang.NullPointerException。
public class JavaApplication58 {
public static void main(String[] args) {
int a[] = null;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i < n; i++) {
a[i - 1] = i;
}
for (int i = 0; i < a.length; i++) {
System.out.println("" + a[i]);
}
}
}