Catching Errors
And prints like this
Enter Mark
(minus sign inputted to check for typing mistake) -
Wrong type of input
Exception in thread InputMismatchException blah blah
Here is the code
public static void GetID() //Function called to collect the student ID and eight marks
{
for (int c = 0; c < 2;c++)
{
System.out.println("Please Enter the student ID");
studentID[c] = kybd.next();
System.out.println("Please enter the eight exams marks");
for (int a = 0; a < 8; ++a)
{
System.out.println("Enter mark" + " " +( a + 1) + " ");
Error();
marks[c][a] = kybd.nextInt();
if (marks[c][a] > 20)
{
System.out.println("Entry out of score limit");
a = a ;
c = c ;
System.out.println("Enter mark" + " " +( a + 1) + " ");
Error();
marks[c][a] = kybd.nextInt();
}
else
if(marks[c][a] < -1 | marks[c][a] == 0)
{
System.out.println("Entry out of score limit");
a = a ;
c = c ;
System.out.println("Enter mark" + " " +( a + 1) + " ");
Error();
marks[c][a] = kybd.nextInt();
}
}
}
Display();
}
public static void Error()
{
try
{
marks[c][a] = kybd.nextInt();
}
catch (InputMismatchException ime)
{
System.out.println("Wrong type of input");
}
}

