Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package main;
- /**
- *
- * @author markjasongalang
- */
- import java.util.Scanner;
- class InvalidGradeException extends Exception {
- public String PrintErrorMessage() {
- return "Grade should be between 0 to 100 only.";
- }
- }
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- try {
- System.out.print("Enter grade: ");
- int grade = in.nextInt();
- if (grade < 0 || grade > 100) {
- throw new InvalidGradeException();
- }
- System.out.println("Grade: " + grade);
- } catch (InvalidGradeException e) {
- System.out.println(e.PrintErrorMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement