Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/06/2012, 11:00
Avatar de diegovazgonz
diegovazgonz
 
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 7 meses
Puntos: 11
Pregunta Problema de ejecucion

Buenas tardes, escribi el siguiente programa y me da fallo

Código C:
Ver original
  1. import java.io.IOException;
  2.  
  3.  
  4. public class inicio {
  5. static long saldo;
  6.     public static void main(String[] args) throws IOException
  7.     {
  8.     System.out.println("Buenos Días, bienvenido a su banco \n");
  9.     int opcion=0;
  10.    
  11.     do
  12.     {
  13.         System.out.println("\n\n¿Que quiere hacer\n1)Ingresar\n2)Retirar\n3)Conocer saldo\n4)Salir");
  14.         opcion=System.in.read();
  15.         switch (opcion){
  16.         case 1:     ingresar();
  17.         break;
  18.         case 2:
  19.             retirar();
  20.             break;
  21.         case 3:
  22.             mostrar();
  23.             break;
  24.         case 4:
  25.             opcion =4;
  26.             break;
  27.         };
  28.        
  29.     }
  30.     while(opcion != 4);
  31.        
  32.     }
  33.     static void ingresar() throws IOException{
  34.         long cantidad =0;
  35.         System.out.print("\nCantidad:");
  36.         cantidad = System.in.read();
  37.     saldo += cantidad;
  38.     mostrar();
  39.     }
  40.     static void mostrar(){
  41.         System.out.print("\n" + saldo + "\n");
  42.     };
  43.     static void retirar()throws IOException{
  44.         long cantidad =0;
  45.         System.out.print("\nCantidad:");
  46.         cantidad = System.in.read();
  47.         if(saldo< cantidad)
  48.             System.out.print("\nNo tiene suficiente dinero\n");
  49.         else
  50.             saldo -= cantidad;
  51.         mostrar();
  52.     };
  53.    
  54. };

Cuando lo ejecuto me da :
Código HTML:
Ver original
  1. Buenos Días, bienvenido a su banco
  2.  
  3.  
  4. ¿Que quiere hacer
  5. 1)Ingresar
  6. 2)Retirar
  7. 3)Conocer saldo
  8. 4)Salir
y si pulso 2 por ejemplo me da esto, donde esta el fallo
Código HTML:
Ver original
  1. Buenos Días, bienvenido a su banco
  2.  
  3.  
  4.  
  5. ¿Que quiere hacer
  6. 1)Ingresar
  7. 2)Retirar
  8. 3)Conocer saldo
  9. 4)Salir
  10. 2
  11.  
  12.  
  13. ¿Que quiere hacer
  14. 1)Ingresar
  15. 2)Retirar
  16. 3)Conocer saldo
  17. 4)Salir
  18.  
  19.  
  20. ¿Que quiere hacer
  21. 1)Ingresar
  22. 2)Retirar
  23. 3)Conocer saldo
  24. 4)Salir
  25.  
  26.  
  27. ¿Que quiere hacer
  28. 1)Ingresar
  29. 2)Retirar
  30. 3)Conocer saldo
  31. 4)Salir
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com