Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package util;
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7.  
  8. public class Input {
  9.  
  10.     public static String readString() {
  11.         try {
  12.             BufferedReader in = new BufferedReader(new InputStreamReader(
  13.                     System.in));
  14.             String s = in.readLine();
  15.             return s;
  16.         } catch (IOException ex) {
  17.             System.out.println(ex.getMessage());
  18.         }
  19.         return "- Nothing to read -";
  20.     }
  21.  
  22.     public static String readString(String prompt) {
  23.         System.out.print(prompt);
  24.         return readString();
  25.     }
  26.  
  27.     public static String printAsOften(String what, int howOften) {
  28.         StringBuffer sb = new StringBuffer(howOften * what.length());
  29.         for (int i = 0; i < howOften; i++) {
  30.             sb.append(howOften);
  31.         }
  32.  
  33.         return sb.toString();
  34.     }
  35.  
  36.  
  37.     public static int readInt() {
  38.         return Integer.valueOf(readString()).intValue();
  39.     }
  40.  
  41.     public static int readInt(String prompt) {
  42.         return Integer.valueOf(readString(prompt)).intValue();
  43.     }
  44.  
  45.     public static float readFloat() {
  46.         return Float.valueOf(readString()).floatValue();
  47.     }
  48.  
  49.     public static float readFloat(String prompt) {
  50.         return Float.valueOf(readString(prompt)).floatValue();
  51.     }
  52.  
  53.     public static double readDouble() {
  54.         return Double.valueOf(readString()).doubleValue();
  55.     }
  56.  
  57.     public static double readDouble(String prompt) {
  58.         return Double.valueOf(readString(prompt)).doubleValue();
  59.     }
  60.  
  61.     public static String getLineSeperator() {
  62.         return System.getProperty("line.separator");
  63.     }
  64.  
  65.     public static boolean isEmpty(String text) {
  66.         return text.length() == 0 || text == null;
  67.     }
  68.  
  69.     public static boolean isInt(String text) {
  70.         boolean isInt = false;
  71.         try {
  72.             Integer.parseInt(text);
  73.  
  74.             isInt = true;
  75.         } catch (NumberFormatException exception) {
  76.             isInt = false;
  77.         }
  78.         return isInt;
  79.     }
  80.  
  81.     public static int toInt(String text) {
  82.         int ret = 0;
  83.         try {
  84.             ret = Integer.parseInt(text);
  85.         } catch (NumberFormatException exception) {
  86.             return 0;
  87.         }
  88.         return ret;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement