miércoles, 25 de mayo de 2011

Sentencias Switch. ingresar dos numeros y un signo, suma,resta,multiplicacion,division

import javax.swing.JOptionPane;
public class ejerc02 {
    public static void main(String[] args) {
    String entrada=JOptionPane.showInputDialog("Ingresar numero1");
    double num1=Double.parseDouble(entrada);
    entrada=JOptionPane.showInputDialog("ingresar numero2");
    double num2=Double.parseDouble(entrada);
    String signo=JOptionPane.showInputDialog("Ingresa la poperacion:1-suma/ 2-resta/ 3-multiplicacion/ 4-division");
    int operacion=Integer.parseInt(signo);
    switch(operacion)
     {
    case 1:JOptionPane.showMessageDialog(null,"suma"+(num1+num2));break;
    case 2:JOptionPane.showInputDialog("resta" +(num1-num2));break;
    case 3:JOptionPane.showInputDialog("multiplicacion" +(num1*num2));break;
    case 4:JOptionPane.showInputDialog("division" +(num1/num2));break;

    default:JOptionPane.showInternalMessageDialog(null,"operacion no valida");
     }
   }
}

No hay comentarios:

Publicar un comentario