ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Clase Leer Java


Enviado por   •  27 de Septiembre de 2013  •  476 Palabras (2 Páginas)  •  448 Visitas

Página 1 de 2

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package javaapplication1;

/**

*

* @author adminlocal

*/

import java.io.*;

public class Leer {

private 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 la tecla Entrar

sdato = flujoE.readLine();

}

catch(IOException e)

{

System.err.println("Error: " + e.getMessage());

}

return sdato; // devolver el dato tecleado

}

public static short datoShort()

{

try

{

return Short.parseShort(dato());

}

catch(NumberFormatException e)

{

return Short.MIN_VALUE; // valor más pequeño

}

}

public static int datoInt()

{

try

{

return Integer.parseInt(dato());

}

catch(NumberFormatException e)

{

return Integer.MIN_VALUE; // valor más pequeño

}

}

public static long datoLong()

{

try

{

return Long.parseLong(dato());

}

catch(NumberFormatException e)

{

return Long.MIN_VALUE; // valor más pequeño

}

}

public static float datoFloat()

{

try

{

Float f = new Float(dato());

return f.floatValue();

}

catch(NumberFormatException e)

{

return Float.NaN; // No es un Número; valor float.

}

}

public static double datoDouble()

{

try

{

Double d = new Double(dato());

return d.doubleValue();

}

catch(NumberFormatException e)

{

return Double.NaN; // No es un Número; valor double.

}

}

public static String datoString()

{

String s = new String(dato());

return s;

}

}

...

Descargar como  txt (1.9 Kb)  
Leer 1 página más »
txt