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