public class Leer {
public static String dato(){
String sdato = "";
try{
//Definir un flujo de caracteres de entrada: flujoE
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader flujoE = new BufferedReader(isr);
//Leer la entrada finaliza al pulsar enter
sdato = flujoE.readLine();
}
catch(IOException e){
System.err.println("Error: " + e.getMessage());
}
return sdato;
}
public static float datoFloat(){
try{
return Float.parseFloat(dato());
}
catch(NumberFormatException e){
return Float.NaN; //no es un numero: valor float
}
}
public static double datoDouble(){
try{
return Double.parseDouble(dato());
}
catch(NumberFormatException e){
return Double.NaN; //No es un numero:valor double
}
}
public static int datoInt(){
try{
return Integer.parseInt(dato());
}
catch(NumberFormatException e){
return Integer.MIN_VALUE; //valor mas pequeño
}
}
}