Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exepciones;
- import java.util.Scanner;
- import java.util.InputMismatchException;
- /**
- *
- * @author Jesús Darío Rodríguez
- */
- public class Exepciones {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner entrada = new Scanner(System.in);
- try{
- System.out.println("Introduzca el primer numero ");
- double n1= entrada.nextDouble();
- System.out.println("Introduzca el segundo numero ");
- double n2= entrada.nextDouble();
- if (n2 == 0) throw new ArithmeticException(); //excepcion artimetica
- double res = n1/n2;
- System.out.println("el resultado es:"+res);
- } catch(ArithmeticException e){
- System.out.println("no se puede dividir entre 0:");
- }catch (InputMismatchException e ) { // excepcion de error de entrada
- System.out.println("Debe de Introducir un numero");
- }finally{
- System.out.println("Proceso completado");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement