package exceptions;
import java.util.*;
public class Division {
double division(int a,int b)
{
return a/b;
}
public static void main(String[] args) {
Division d=new Division();
Scanner sc=new Scanner(System.in);
System.out.println("Enter First Number: ");
int a=sc.nextInt();
System.out.println("Enter Second Number: ");
int b=sc.nextInt();
try
{
double res=d.division(a,b);
System.out.println("Result: "+res);
}catch(ArithmeticException ae)
{
System.out.println("Divide By Zero "+ae);
}
}
}
import java.util.*;
public class Division {
double division(int a,int b)
{
return a/b;
}
public static void main(String[] args) {
Division d=new Division();
Scanner sc=new Scanner(System.in);
System.out.println("Enter First Number: ");
int a=sc.nextInt();
System.out.println("Enter Second Number: ");
int b=sc.nextInt();
try
{
double res=d.division(a,b);
System.out.println("Result: "+res);
}catch(ArithmeticException ae)
{
System.out.println("Divide By Zero "+ae);
}
}
}
0 comments:
Post a Comment