-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExcepcionApp3.java
28 lines (27 loc) · 944 Bytes
/
ExcepcionApp3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class ExcepcionApp3 {
public static void main(String[] args) {
String str1="120";
String str2="3";
String respuesta;
int numerador, denominador, cociente;
try{
numerador=Integer.parseInt(str1);
denominador=Integer.parseInt(str2);
rango(numerador, denominador);
cociente=numerador/denominador;
respuesta=String.valueOf(cociente);
}catch(NumberFormatException ex){
respuesta="Se han introducido caracteres no numéricos";
}catch(ArithmeticException ex){
respuesta="División entre cero";
}catch(ExcepcionIntervalo ex){
respuesta=ex.getMessage();
}
System.out.println(respuesta);
}
static void rango(int num, int den)throws ExcepcionIntervalo{
if((num>100)||(den<-5)){
throw new ExcepcionIntervalo("Números fuera de rango");
}
}
}