1
0

InteractiveIO.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. /**
  6. *
  7. * @author LH
  8. */
  9. import java.io.*;
  10. import java.math.BigDecimal;
  11. import java.math.BigInteger;
  12. class InteractiveIO
  13. {
  14. private static BufferedReader br = new BufferedReader(new InputStreamReader(
  15. System.in));;
  16. public static void write(String s) throws Exception
  17. {
  18. writeAndFlush(s);
  19. }
  20. public static String promptAndRead(String s) throws
  21. Exception
  22. {
  23. writeAndFlush(s);
  24. return br.readLine();
  25. }
  26. private static void writeAndFlush(String s) throws
  27. Exception
  28. {
  29. System.out.println(s);
  30. System.out.flush();
  31. }
  32. public static int promptForInt(String s) throws
  33. Exception
  34. {
  35. return Integer.parseInt(promptAndRead(s.trim()));
  36. }
  37. public static long promptForLong(String s) throws
  38. Exception
  39. {
  40. return Long.parseLong(promptAndRead(s.trim()));
  41. }
  42. public static float promptForFloat(String s) throws
  43. Exception
  44. {
  45. return Float.parseFloat(promptAndRead(s.trim()));
  46. }
  47. public static double promptForDouble(String s) throws
  48. Exception
  49. {
  50. return Double.parseDouble(promptAndRead(s.trim()));
  51. }
  52. public static BigDecimal promptForBigDecimal(String s) throws
  53. Exception
  54. {
  55. return new BigDecimal(promptAndRead(s.trim()));
  56. }
  57. public static BigInteger promptForBigInteger(String s) throws
  58. Exception
  59. {
  60. return new BigInteger(promptAndRead(s.trim()));
  61. }
  62. }