Advertisement
Metziop

programa completo u3a3

May 17th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package exepciones;
  2. import java.util.Scanner;
  3. import java.util.InputMismatchException;
  4.  
  5. /**
  6.  *
  7.  * @author Jesús Darío Rodríguez
  8.  */
  9. public class Exepciones {
  10.  
  11.     /**
  12.      * @param args the command line arguments
  13.      */
  14.    
  15.     public static void main(String[] args) {
  16.         Scanner entrada = new Scanner(System.in);
  17.         try{
  18.         System.out.println("Introduzca el primer numero ");
  19.         double n1= entrada.nextDouble();
  20.         System.out.println("Introduzca el segundo numero ");
  21.         double n2= entrada.nextDouble();
  22.         if (n2 == 0) throw new ArithmeticException(); //excepcion artimetica
  23.         double res = n1/n2;
  24.         System.out.println("el resultado es:"+res);
  25.         } catch(ArithmeticException e){
  26.            System.out.println("no se puede dividir entre 0:");
  27.         }catch (InputMismatchException e ) { // excepcion de error de entrada
  28.                System.out.println("Debe de Introducir un numero");
  29.        }finally{
  30.             System.out.println("Proceso completado");
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement