Untitled

mail@pastecode.io avatarunknown
plain_text
13 days ago
969 B
0
Indexable
Never
import java.util.Scanner;

public class Excepciones {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double valores [] = {3,2,-4,8,4,0,6};
        try{
            int a =  sc.nextInt();
            int b = a+1;
            if(a ==6) throw  new MiException();
            double division2 = valores[a]/valores[b];
            System.out.println("La division es: " + division2);
        }catch(ArithmeticException e){
            System.out.println("Error aritmetico");
        }catch(IndexOutOfBoundsException e){
            System.out.println("Fuera de rango");
        }catch (MiException e){
            System.out.println(e.toString());
        }catch (Exception e){
            System.out.println("Otro error");
        }

    }
}

public class MiException extends Exception {

    public String toString(){
       return "No hay valores a la derecha del indice ingresado";
    }