Will rate as lifesaver How do I add the following to my code: Throws an exceptio
ID: 3618996 • Letter: W
Question
Will rate as lifesaverHow do I add the following to my code:
Throws an exception if the user enters a nonnumeric value and asksthe user to reenter the value
Throws an exception if the user enters a grade that is not in therange 0-100 and asks the user to reenter the value
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String letter = "A";
int grade = 0 ;
int avg = 0;
System.out.println("Enter first name: ");
String first = in.next();
System.out.println("Enter last name: ");
String last = in.next();
for (int i = 0; i < 3; i++){
System.out.println("Enter grade:");
int grades = in.nextInt();
grade += grades;
}
}
}