import java.util.Scanner;
public class Divisor{
public static void main(String[] args){
Scanner inp=new Scanner(System.in);
System.out.println("Enter the First number");
double x=inp.nextDouble();
System.out.println("Enter the Second number");
double y=inp.nextDouble();
Divisor d= new Divisor();
d.divide(x,y);
}
public void divide(double x, double y){
double result=0;
try{
if(y==0){
throw new ArithmeticException("Divisor Cannot Be Zero");
}
}
catch(ArithmeticException ae){
System.out.println("Exception:Divisor Cannot be ZERO "+"\n Enter the Divisor again");
Scanner inp=new Scanner(System.in);
y=inp.nextDouble();
}
result=(x/y);
System.out.println("Result of the divsion is "+result);
}
}
public class Divisor{
public static void main(String[] args){
Scanner inp=new Scanner(System.in);
System.out.println("Enter the First number");
double x=inp.nextDouble();
System.out.println("Enter the Second number");
double y=inp.nextDouble();
Divisor d= new Divisor();
d.divide(x,y);
}
public void divide(double x, double y){
double result=0;
try{
if(y==0){
throw new ArithmeticException("Divisor Cannot Be Zero");
}
}
catch(ArithmeticException ae){
System.out.println("Exception:Divisor Cannot be ZERO "+"\n Enter the Divisor again");
Scanner inp=new Scanner(System.in);
y=inp.nextDouble();
}
result=(x/y);
System.out.println("Result of the divsion is "+result);
}
}
No comments:
Post a Comment