Advertisement
Guest User

juangonza

a guest
Feb 18th, 2010
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. /**
  2.  *
  3.  * @author saul aponte
  4.  */
  5. package calc;
  6.  
  7. import java.io.*;
  8. public class Leer {
  9.     public static String dato(){
  10.         String sdato = "";
  11.         try {
  12.             InputStreamReader isr = new InputStreamReader(System.in);
  13.             BufferedReader flujoE = new BufferedReader(isr);
  14.             sdato = flujoE.readLine();
  15.         }
  16.         catch (IOException e){
  17.             System.err.println("Error: " + e.getMessage());
  18.         }
  19.         return sdato;
  20.     }
  21.    
  22.     public static short datoShort(){
  23.         try {
  24.             return Short.parseShort(dato());
  25.         }
  26.         catch (NumberFormatException e){
  27.             return Short.MIN_VALUE;
  28.         }
  29.     }
  30.  
  31.     public static int datoInt(){
  32.         try {
  33.             return Integer.parseInt(dato());
  34.         }
  35.         catch (NumberFormatException e){
  36.             return Integer.MIN_VALUE;
  37.         }
  38.     }
  39.  
  40.     public static long datoLong(){
  41.         try {
  42.             return Long.parseLong(dato());
  43.         }
  44.         catch (NumberFormatException e){
  45.             return Long.MIN_VALUE;
  46.         }
  47.     }
  48.  
  49.     public static float datoFloat(){
  50.         try {
  51.             Float f = new Float(dato());
  52.             return f.floatValue();
  53.         }
  54.         catch (NumberFormatException e){
  55.             return Float.NaN;
  56.         }
  57.     }
  58.  
  59.     public static double datoDouble(){
  60.         try {
  61.             Double d = new Double(dato());
  62.             return d.doubleValue();
  63.         }
  64.         catch (NumberFormatException e){
  65.             return Double.NaN;
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement