Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday, 20 May 2015

example to throw ArithmeticException in java

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);
}
}

No comments:

Post a Comment