java program 6
java program 6:
itprofessionalsrocks.blogspot.com
WAP to define an exception called "MarksOutOfBound" exception that is thrown if the marks are out of bound.
import java.lang.Exception;
import java.util.Scanner;
import java.io.*;
class MarksOutOfBound extends Exception
{
MarksOutOfBound(String message)
{super(message);
}
}
class marksexcep
{
public static void main(String args[])
{
Scanner obj=new Scanner(System.in);
int[] a=new int[6];
System.out.println("enter marks for five subjects") ;
for(int i=0;i<5;i++)
{a[i]=obj.nextInt();
try
{if(a[i]>100)
{
throw new MarksOutOfBound("marks are out of bound");
}
}
catch (MarksOutOfBound e)
{System.out.println("Caught the exception");
}
}
}
}
Comments
Post a Comment