GreysitoErPutoAmo

EJERCICIO 1 EXCEPCIONES JAVA

Apr 20th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. package ejercicio1;
  2.  
  3. import java.util.InputMismatchException;
  4. import java.util.Scanner;
  5.  
  6. public class e1 {
  7.  
  8.    
  9.     public static void main(String[] args) {
  10.        
  11.        
  12.         double a, b,  c = 0;
  13.            
  14.         boolean cont = false;
  15.        
  16.         while (cont==false){
  17.         Scanner entrada = new Scanner(System.in);
  18.        
  19.         try {
  20.             System.out.println("Introduzca a: ");
  21.             a = entrada.nextDouble();
  22.             System.out.println("Introduzca b: ");
  23.             b = entrada.nextDouble();
  24.                        
  25.             cont= true;
  26.            
  27.             c=a/b;
  28.             System.out.println(c);
  29.         }
  30.         catch (InputMismatchException e){
  31.             System.out.println("Debes introducir un número");
  32.             }
  33.         catch (ArithmeticException e){
  34.             System.out.println("No se puede dividir entre 0");
  35.             }
  36.        
  37.     }
  38.        
  39. }
  40. }
Add Comment
Please, Sign In to add comment