dorbird

Java Hilfs Class

Nov 14th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | None | 0 0
  1. /**
  2. * macht das Einlesen von Einfachen Daten einfacher
  3. * durch Verdecken des Exception-Handlings
  4. */
  5. import java.io.*;
  6. public class IO
  7. {
  8.     public static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  9.     public static String eingabe = "";
  10.     // Einlesen eines char
  11.     public static char readChar()
  12.     {
  13.        try
  14.     {
  15.                 eingabe = input.readLine();
  16.             return eingabe.charAt(0);
  17.         }
  18.         catch(Exception e)
  19.         {
  20.             return '\0';
  21.         }
  22.     }
  23. // Einlesen eines short
  24.     public static short readShort()
  25.     {
  26.         try {
  27.             eingabe = input.readLine();
  28.             Integer string_to_short = new Integer(eingabe);
  29.             return (short)string_to_short.intValue();
  30.         }
  31.             catch (Exception e)
  32.         {
  33.             return 0;
  34.         }
  35.     }
  36. // Einlesen eines int
  37.     public static int readInt()
  38.     {
  39.         try
  40.         {
  41.             eingabe = input.readLine();
  42.             Integer string_to_int = new Integer(eingabe);
  43.             return string_to_int.intValue();
  44.         }
  45.         catch (Exception e)
  46.         {
  47.             return 0;
  48.         }
  49.     }
  50. // Einlesen eines long
  51.     public static long readLong()
  52.     {
  53.         try
  54.         {
  55.             eingabe = input.readLine();
  56.             Long string_to_long = new Long(eingabe);
  57.             return string_to_long.longValue();
  58.         }
  59.         catch (Exception e)
  60.         {
  61.             return 0L;
  62.         }
  63.     }
  64. // Einlesen eines float
  65.     public static float readFloat() {
  66.         try
  67.         {
  68.             eingabe = input.readLine();
  69.             Float string_to_float = new Float(eingabe);
  70.             return string_to_float.floatValue();
  71.         }
  72.         catch (Exception e)
  73.         {
  74.             return 0.0F; }
  75.         }
  76. // Einlesen eines double
  77.     public static double readDouble()
  78.     {
  79.         try
  80.         {
  81.             eingabe = input.readLine();
  82.             Double string_to_double = new Double(eingabe);
  83.             return string_to_double.doubleValue();
  84.         }
  85.         catch (Exception e)
  86.         {
  87.             return 0.0;
  88.         }
  89.     }
  90. // Einlesen eines string
  91.     public static String readString()
  92.     {
  93.         try
  94.         {
  95.             return input.readLine();
  96.         }
  97.         catch (Exception e)
  98.         {
  99.             return "";
  100.         }
  101.     }
  102. // Ausgabe
  103.     public static void println(String s)
  104.     {
  105.         System.out.println(s);
  106.     }
  107.  
  108.     public static void print(String s)
  109.     {
  110.         System.out.print(s);
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment