class ErrorHandling{
private int x;
private int y;
public void setData(int a,int b){
x=a;
y=b;
}
public void divide(){
try{
double div=x/y;
System.out.println(x+" / "+y+" = "+div);
}
catch(Exception e){
System.out.println("A number cannot be divided by 0");
}
}
}
public class Main
{
public static void main(String[] args) {
ErrorHandling e=new ErrorHandling();
e.setData(23,0);
e.divide();
e.setData(56,8);
e.divide();
}
}
Comments
Leave a comment