You are on page 1of 2

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package emmanuel.ejercicio1;
import java.util.Scanner;
/**
*
* @author Del Valle
*/
public class calculadora {
public static void suma(){
int A,B,res;
Scanner BUFF = new Scanner(System.in);
System.out.println("INTRODUZCA UN NUMERO A OPERAR");
A = BUFF.nextInt();
System.out.println("INTRODUZCA NUMERO A OPERAR");
B = BUFF.nextInt();
res=A+B;
System.out.println("El resultado de la suma es : "+res);
}
public static void resta(){
int A,B,res;
Scanner BUFF = new Scanner(System.in);
System.out.println("INTRODUSCA NUMEROS 1 A OPERAR");
A = BUFF.nextInt();
System.out.println("INTRODUSCA NUMEROS 2 A OPERAR");
B = BUFF.nextInt();
res=A-B;
System.out.println("El resultado de la resta es : "+res);
}
public static void mult(){
int A,B,res;
Scanner BUFF = new Scanner(System.in);
System.out.println("INTRODUZCA NUMERO A OPERAR");
A = BUFF.nextInt();
System.out.println("INTRODUZCA NUMERO A OPERAR");
B = BUFF.nextInt();
res=A*B;
System.out.println("El resultado de la multiplicacin es : "+res);
}
public static void div(){
float res;
int A,B;
Scanner BUFF = new Scanner(System.in);
System.out.println("INTRODUZCA NUMERO A OPERAR");
A = BUFF.nextInt();
System.out.println("INTRODUZCA NUMERO A OPERAR");
B = BUFF.nextInt();
if(B==0){
System.out.println("no se puede dividir entre 0");
}
else{

res=A/B;
System.out.println("El resultado de la divisin es : "+res);
}
}
public static void fact(){
int res =1;
int i,A;
Scanner BUFF = new Scanner(System.in);
System.out.println("INTRODUZCA NUMERO A OPERAR");
A = BUFF.nextInt();
for(i=A;i>=1;i--){
res=i*res;
}
System.out.println("el resultado del factorial es="+res);
}
public static void calculadora(){
Scanner BUFF1 = new Scanner(System.in);
int num;
System.out.println("\t CALCULADORA \n 1.SUMAR\n 2.restar \n 3.MULTIPLICA
R \n 4.DIVIDIR \n 5.FACTORIAL");
num = BUFF1.nextInt();
switch (num) {
case 1:
suma();
break;
case 2: resta();
break;
case 3: mult();
break;
case 4: div();
break;
case 5: fact();
break;
default: System.out.println("No se selecciono una opcion valida");
}
}
public static void main(String[] args) {
calculadora();
}
}

You might also like