Ver Mensaje Individual
  #4 (permalink)  
Antiguo 11/02/2005, 09:46
ryky21
 
Fecha de Ingreso: febrero-2005
Mensajes: 6
Antigüedad: 19 años, 3 meses
Puntos: 0
usa esta clase

si usas esta clase te ira mucho mejor. asi te permitira recoger todo tipo de datos usalo de esta forma.
int a=LeerTeclado.readInt();
String a=LeerTeclado.readLine();
double a=LeerTeclado.readDouble();

y asi todos sus metodos te ayudaran a recoger diferentes variables que tiene java

public class LeerTeclado
{
public static String readLine()
{
char c;
String cadena = (String) "";
try
{
while( (c = (char) System.in.read()) != '\r' )
cadena += c;
System.in.read();
}
catch( Exception e )
{
System.out.println("error de entrada de datos!!!!!!!!");
System.exit(0);
}
return cadena;
}
public static int readInt()
{
try
{
return Integer.parseInt(readLine() );
}
catch( Exception e )
{
System.out.println( "No es un numero entero valido!!!!!!!!");
System.exit(1);
return 0;
}
}
public static double readDouble()
{
try
{
return Double.parseDouble(readLine() );
}
catch( Exception e )
{
System.out.println( "No es un numero real valido!!!!!!!!");
System.exit(2);
return 0.0;
}
}
public static char readChar()
{
try
{
String aux = new String(readLine() );
if ( aux.length() == 1 )
return aux.charAt(0);
else
{
System.out.println("Caracter no reconocido!!!!!!!!!");
System.exit(3);
return 0;
}
}
catch( Exception e )
{
System.out.println( "Caracter no reconocido!!!!!!!!" );
System.exit(4);
return 0;
}
}
}