Ejercicio Calculadora en JAVA
Ejercicio de Calculadora hecho con Vectores y Métodos
import java.util.Scanner;
public class Calculadora {
public static double vlr1, vlr2;
public static Scanner sc = new Scanner(System.in);
public static void main(String arg[]){
Calculadora cal = new Calculadora();
System.out.print("Ingrese el Valor 1 ");
vlr1 = sc.nextDouble();
System.out.print("Ingrese el Valor 2 ");
vlr2 = sc.nextDouble();
System.out.print("La suma de " + vlr1 + " y " + vlr2 + " es " + sumar());
System.out.print(" La resta de " + vlr1 + " y " + vlr2 + " es " + restar());
System.out.print(" La multiplicacion de " + vlr1 + " y " + vlr2 + " es " + multiplicar());
System.out.print(" La division de " + vlr1 + " y " + vlr2 + " es " + dividir());
}
public static double sumar(){
return (vlr1 + vlr2);
}
public static double restar(){
return(vlr1 - vlr2);
}
public static double multiplicar(){
return (vlr1 * vlr2);
}
public static double dividir(){
return (vlr1/vlr2);
}
}
Código:
import java.util.Scanner;
public class Calculadora {
public static double vlr1, vlr2;
public static Scanner sc = new Scanner(System.in);
public static void main(String arg[]){
Calculadora cal = new Calculadora();
System.out.print("Ingrese el Valor 1 ");
vlr1 = sc.nextDouble();
System.out.print("Ingrese el Valor 2 ");
vlr2 = sc.nextDouble();
System.out.print("La suma de " + vlr1 + " y " + vlr2 + " es " + sumar());
System.out.print(" La resta de " + vlr1 + " y " + vlr2 + " es " + restar());
System.out.print(" La multiplicacion de " + vlr1 + " y " + vlr2 + " es " + multiplicar());
System.out.print(" La division de " + vlr1 + " y " + vlr2 + " es " + dividir());
}
public static double sumar(){
return (vlr1 + vlr2);
}
public static double restar(){
return(vlr1 - vlr2);
}
public static double multiplicar(){
return (vlr1 * vlr2);
}
public static double dividir(){
return (vlr1/vlr2);
}
}
Comentarios
Publicar un comentario