Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package util;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Input {
- public static String readString() {
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(
- System.in));
- String s = in.readLine();
- return s;
- } catch (IOException ex) {
- System.out.println(ex.getMessage());
- }
- return "- Nothing to read -";
- }
- public static String readString(String prompt) {
- System.out.print(prompt);
- return readString();
- }
- public static String printAsOften(String what, int howOften) {
- StringBuffer sb = new StringBuffer(howOften * what.length());
- for (int i = 0; i < howOften; i++) {
- sb.append(howOften);
- }
- return sb.toString();
- }
- public static int readInt() {
- return Integer.valueOf(readString()).intValue();
- }
- public static int readInt(String prompt) {
- return Integer.valueOf(readString(prompt)).intValue();
- }
- public static float readFloat() {
- return Float.valueOf(readString()).floatValue();
- }
- public static float readFloat(String prompt) {
- return Float.valueOf(readString(prompt)).floatValue();
- }
- public static double readDouble() {
- return Double.valueOf(readString()).doubleValue();
- }
- public static double readDouble(String prompt) {
- return Double.valueOf(readString(prompt)).doubleValue();
- }
- public static String getLineSeperator() {
- return System.getProperty("line.separator");
- }
- public static boolean isEmpty(String text) {
- return text.length() == 0 || text == null;
- }
- public static boolean isInt(String text) {
- boolean isInt = false;
- try {
- Integer.parseInt(text);
- isInt = true;
- } catch (NumberFormatException exception) {
- isInt = false;
- }
- return isInt;
- }
- public static int toInt(String text) {
- int ret = 0;
- try {
- ret = Integer.parseInt(text);
- } catch (NumberFormatException exception) {
- return 0;
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement