robeeeert

PRoblema8

Apr 12th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  */
  4.  
  5. package com.mycompany.problema_7;
  6.  
  7. /**
  8.  *
  9.  * @author ianto
  10.  */
  11. import java.util.*;
  12. public class Problema_7 {
  13.  
  14.     public static void main(String[] args) {
  15.         int opcion = 0;
  16.         Scanner entrada = new Scanner(System.in);
  17.         boolean salir = false;
  18.         while(!salir) {
  19.             System.out.println("1. Multiplicación");
  20.             System.out.println("2. División");
  21.             System.out.println("3. Salir");
  22.             System.out.println("Ingrese una opcion");
  23.             opcion = entrada.nextInt();
  24.             switch(opcion){
  25.                 case 1:
  26.                         int numero1, numero2;
  27.                         int res_multi = 0;
  28.                         int contador = 0;
  29.                         System.out.println("\nMULTIPLICACION\n");
  30.                         System.out.println("Ingrese Un Numero");
  31.                         numero1 = entrada.nextInt();
  32.                         System.out.println("Ingrese El Numero Para Multiplicar");
  33.                         numero2 = entrada.nextInt();
  34.                    
  35.                         for(int i = 1; i <= numero2; i++) {
  36.                             res_multi += numero1;
  37.                         }
  38.                         System.out.println("\nResultado: " + res_multi);
  39.                         presioneEnter();
  40.                         break;
  41.                 case 2:
  42.                     int dividendo;
  43.                     int divisor;
  44.                     int cociente = 0;
  45.                     System.out.println("\nDIVISION\n");
  46.                     System.out.println("Ingrese El Dividendo");
  47.                     dividendo = entrada.nextInt();
  48.                     System.out.println("Ingrese El Divisor");
  49.                     divisor = entrada.nextInt();
  50.                     if(divisor == 0){
  51.                         System.out.println("No Se Puede Dividir Entre 0");
  52.                         presioneEnter();
  53.                     }else{
  54.                         while(dividendo >= divisor) {
  55.                             cociente ++;
  56.                             dividendo = dividendo - divisor;
  57.                         }
  58.                         System.out.println("Cociente: " + cociente);
  59.                         System.out.println("Residuo: " + dividendo);
  60.                         presioneEnter();
  61.                     }
  62.                     break;
  63.                 case 3:
  64.                     salir = true;
  65.                     break;
  66.                 default:
  67.                     System.out.println("Opcion No Valida");
  68.             }
  69.         }
  70.     }
  71.     public static void presioneEnter() {
  72.         System.out.println("\nPresione Enter Para Mostrar El Menu Nuevamente");
  73.         Scanner entrada = new Scanner(System.in);
  74.         entrada.nextLine();
  75.     }
  76.    
  77. }
Add Comment
Please, Sign In to add comment