我目前正在尝试创建一个程序,该程序将询问用户注册用户的类数,创建一个数组来存储该数据,然后最终在print语句中显示所有这些信息。我并不担心最终的打印声明,但我似乎无法让数组工作。程序中没有错误,但一旦它要求我输入类号,它返回“线程中的异常”主“java.lang.NullPointerException 在GPAreport.main(GPAreport.java:24)“
下面是代码:
import java.util.*;
public class GPAreport {
public static void main (String [] args) {
int classnumber[] = null;
double gpa[];
String ClassDescription[] = null;
Scanner myScanner = new Scanner(System.in);
String LetterGrade = "";
double GradePoints = 0;
double PercentageGrade = 0;
String currentterm, studentname = "";
int numberofclasses;
System.out.println("Please enter the current term (ex: fall 2011):");
currentterm = myScanner.nextLine();
System.out.println("Please enter Student Name:");
studentname = myScanner.nextLine();
System.out.println("Please enter number of classes:");
numberofclasses = myScanner.nextInt();
for(int i = 0; i <= numberofclasses ; i++){
System.out.println("Input Class Number: " + (i+1));
classnumber[i] = myScanner.nextInt();
System.out.println("Input class description: " + (i+1));
ClassDescription[i] = myScanner.nextLine();
System.out.println("Input percentile grade for: " + classnumber[i]);
PercentageGrade = myScanner.nextDouble();
if ((PercentageGrade < 100) && (PercentageGrade >= 93 )){
LetterGrade = "A";
GradePoints = 4.0;
}
else if ((PercentageGrade > 100)){
LetterGrade = "A+";
GradePoints = 4.0;
}
else if ((PercentageGrade < 93) && (PercentageGrade >= 90 )){
LetterGrade = "A-";
GradePoints = 4.0;
}
else if ((PercentageGrade < 90) && (PercentageGrade >= 83 )){
LetterGrade = "B";
GradePoints = 3.0;
}
else if ((PercentageGrade < 83) && (PercentageGrade >= 80 )){
LetterGrade = "B-";
GradePoints = 3.0;
}
else if ((PercentageGrade < 80) && (PercentageGrade >= 73 )){
LetterGrade = "C";
GradePoints = 2.0;
}
else if ((PercentageGrade < 73) && (PercentageGrade >= 70 )){
LetterGrade = "C-";
GradePoints = 2.0;
}
else if ((PercentageGrade < 70) && (PercentageGrade >= 63 )){
LetterGrade = "D";
GradePoints = 1.0;
}
else if ((PercentageGrade < 63) && (PercentageGrade >= 60 )){
LetterGrade = "D-";
GradePoints = 1.0;
}
else if ((PercentageGrade < 60) && (PercentageGrade >= 0)){
LetterGrade = "F";
GradePoints = 0;
}
else if (PercentageGrade < 0){
System.out.println("That is not a valid score. Please try again");
}
}
}
}