So I've been on this problem for hours now and can't seem to figure out how to get this if statement to work. I'm trying to throw GradeException() which does work. But in order to do that I needed to toss an else statement on my if statement. The if statement works perfectly fine. I just can't get the else portion to work. GradeException is another class that I have. I know the class is right so it can't be a problem with that. Can someone explain what I'm doing wrong please? This is in Java by the way.
package testgrade;
import java.util.Scanner;
public class TestGrade
{
public static void main(String[] args)
{
int[] studentId = new int[]{10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008,
10009, 10010};
String letterGrade;
Scanner input = new Scanner(System.in);
try
{
for(int i = 0; i < studentId.length; i++)
{
System.out.print("Enter a letter grade for student " + studentId[i] + ": ");
letterGrade = input.nextLine();
if(letterGrade.equals(GradeException.gradeArray[i]));
{
System.out.println("Student " + studentId[i] + " received a grade of " + letterGrade);
}
else // <-- This is the else that won't work. I've spent hours trying and can't figure out why
{
throw new GradeException();
}
}
}
catch(GradeException exception)
{
System.out.println("Invalid entry! Please enter the proper letter grade");
}
}
}
Aucun commentaire:
Enregistrer un commentaire