Advertisement
FacundoReyes

Clase 2 Ing de variables + string

Mar 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication11;
  7. import java.util.Scanner;
  8. /**
  9.  *
  10.  * @author educacionit
  11.  */
  12. public class JavaApplication11 {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.        
  19.         Scanner teclado = new Scanner(System.in);
  20.        
  21.         /*
  22.         int edad;
  23.        
  24.        
  25.        
  26.         edad = teclado.nextInt();//si necesito que el usuario ingrese un numero
  27.        
  28.         String usuario = teclado.next();//se utiliza para el string
  29.        
  30.         */
  31.        
  32.        
  33.         int n1, int n2;
  34.        
  35.         System.out.println("Ingrese primer numero");
  36.         n1=teclado.nextInt();
  37.         System.out.println("Ingrese segundo numero");
  38.         n2=teclado.nextInt();
  39.        
  40.         System.out.println("\n1. suma \n2. resta\n3. multiplica\n4. divide");
  41.         int opcion=teclado.nextInt();
  42.         switch(opcion){
  43.             case 1:
  44.                 System.out.println("Suma: " + (n1+n2));
  45.                 break;
  46.             case 2:
  47.                 System.out.println("Resta: "+ (n1-n2));
  48.                 break;
  49.             case 3:
  50.                 System.out.println("Producto: "+ (n1*n2));
  51.                 break;
  52.             case 4:
  53.                 System.out.println("Division: "+ (n1/n2));
  54.                 break;
  55.            default:
  56.                System.out.println("Opcion invalida");
  57.                break;
  58.         }
  59.        
  60.     }
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement