Advertisement
ilsilion

2

Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3.  
  4. public class JavaApplication219 {
  5.  
  6.     public static void main(String[] args) {
  7.        
  8.         Scanner reader = new Scanner(System.in);
  9.         double numero1 = 0;
  10.         double numero2 = 0;
  11.         double resultado=0;
  12.        
  13.     Scanner sn = new Scanner(System.in);
  14.     boolean salir = false;
  15.     int opcion; //Guardaremos la opcion del usuario
  16.          
  17.    
  18.      
  19.  
  20.         while (!salir) {
  21.                    
  22.  
  23.            
  24.             System.out.println("\n1. Multiplicar");
  25.             System.out.println("2. Dividir");
  26.             System.out.println("3. Salir");
  27.            
  28.            
  29.  
  30.             try {
  31.  
  32.                 System.out.println("\nEscribe una de las opciones");
  33.                 opcion = sn.nextInt();
  34.  
  35.                 switch (opcion) {
  36.                     case 1:
  37.                         System.out.println("HAS SELECCIONADO MULTIPLICAR \n");
  38.                         System.out.println("\nIntroduce el primer número:");          
  39.                         numero1 = reader.nextInt();
  40.                          
  41.                         System.out.println("Introduce el segundo número:");
  42.                         numero2 = reader.nextInt();
  43.                         resultado = numero1*numero2;
  44.                         System.out.println("\nLa Multiplicacion  es " + numero1 + " * " + numero2 + " = " + resultado);
  45.                         break;
  46.                     case 2:
  47.                         System.out.println("\nHAS SELECCIONADO DIVIDIR\n");
  48.                        
  49.                         System.out.println("\nIntroduce el primer número:");          
  50.                         numero1 = reader.nextInt();
  51.                          
  52.                         System.out.println("Introduce el segundo número:");
  53.                         numero2 = reader.nextInt();
  54.                        
  55.                         resultado = numero1/numero2;
  56.                         System.out.println("\nLa Division  es " + numero1 + " / " + numero2 + " = " +  Math.round(resultado*Math.pow(10,2))/Math.pow(10,2));
  57.                         break;
  58.                     case 3:
  59.                         salir = true;
  60.                         break;
  61.                     default:
  62.                         System.out.println("\nSolo números entre 1 y 3");
  63.                 }
  64.             } catch (InputMismatchException e) {
  65.                 System.out.println("Debes insertar un número");
  66.                 sn.next();
  67.             }
  68.         }
  69.  
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement