public class Divisao implements IDivisao{
@Override
public int divisao(int a, int b) {
if ( b == 0) {
throw new SeFor0("Divisão por zero não é permitida");
} else if (a == 0) {
throw new SeFor0("Divisão por zero não é permitida");
}
int resultado = a / b;
System.out.println(resultado);
return resultado;
}
}
public class SeFor0 extends RuntimeException {
private String msg;
public SeFor0(String msg) {
this.msg = msg;
}
@Override
public String getMessage() {
return this.msg;
}
}
@Override
public int divisao(int a, int b) {
if ( b == 0) {
throw new ArithmeticException("Divisão por zero não é permitida");
} else if (a == 0) {
throw new ArithmeticException("Divisão por zero não é permitida");
}
int resultado = a / b;
System.out.println(resultado);
return resultado;
}
}