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

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream; import java.io.IOException; public class ReadImageFile {     public static void main(String[] args) {       ...