Tuesday, 17 September 2019

Write a Program for exception Handling in java

                                          Program for Exception Handling in Java using try and catch blocks


1. Open the notepad file.

2. Write the code given below in the file.


import java.util.Scanner;
class Excep
{
public static void main(String args[])
{

int div,a,b;
Scanner input= new Scanner(System.in);
System.out.println("Enter 1st Number");
a=input.nextInt();
System.out.println("Enter 2nd Number");
b=input.nextInt();
try
{
div=a/b;

System.out.println("Division of numbers: "+div);
}
catch(Exception e)
{
System.out.println("Exception is caught.");
System.out.println("\nDivision by zero.");
}
finally
{
System.out.println("This is a program of exception handling.");
}
}
}

3. Now save the file with name Excep.java.







No comments:

Post a Comment

Minor Project Ideas for B.tech Computer Science

B.Tech Minor Project: Data Science using Regression This project uses Linear Regression for continuous prediction and Logistic Regress...