0% found this document useful (0 votes)
5 views1 page

Java Exception Handling: Divide by Zero

The document presents a Java program that reads two integers, a and b, and computes their division while handling exceptions for division by zero. It demonstrates exception handling concepts in Java, including the use of try-catch blocks. The program outputs the result of the division or an error message if b is zero.

Uploaded by

quetiepie7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Java Exception Handling: Divide by Zero

The document presents a Java program that reads two integers, a and b, and computes their division while handling exceptions for division by zero. It demonstrates exception handling concepts in Java, including the use of try-catch blocks. The program outputs the result of the division or an error message if b is zero.

Uploaded by

quetiepie7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOP with Java Lab /21CSL35

PROGRAM :10

10. Write a Java program to read two integers a and b. Compute a/b and print, when b is not zero.
Raise an exception when b is equal to zero.

Aim: Exception handling in java, introduction to throwable class, throw, throws, finally

import [Link].*;
public class TryP
{
int c;
void div(int a,int b)
{
try
{
c=a/b;
[Link]("Result="+c);
}
catch(ArithmeticException e)
{
[Link]("Cannot divide by zero");
}
}
public static void main(String args[])
{
TryP obj=new TryP();
Scanner in=new Scanner([Link]);
[Link]("Enter the values of a and b");
int no1=[Link]();
int no2=[Link]();
[Link](no1,no2);
}
}

OUTPUT:

Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23

You might also like