Thursday, February 29, 2024

Java program to check marks out of Bound exception.

import java.util.Scanner;

public class MarksProcessor {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the marks: ");
        int marks = scanner.nextInt();

        try {
            validateMarks(marks);
            System.out.println("Marks are within the valid range.");
        } catch (MarksOutOfBoundsException e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }

    private static void validateMarks(int marks) throws MarksOutOfBoundsException {
        if (marks > 100) {
            throw new MarksOutOfBoundsException("Marks out of Bound: Marks cannot be greater than 100.");
       }
    }
}

No comments:

Post a Comment

📚 Other Stream Classes in Java जावा में अन्य स्ट्रीम क्लासेस

In Java, apart from basic byte and character streams, there are several specialized stream classes that provide advanced input-output operat...