StdIn.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // Body of StdIn interface.
  3. // This file implements the code of the StdIn.cp file.
  4. // kjg June 2004.
  5. package CP.StdIn;
  6. import java.io.*;
  7. public class StdIn
  8. {
  9. private static BufferedReader rdr =
  10. new BufferedReader(new InputStreamReader(System.in));
  11. public static void ReadLn(char[] arr) throws IOException {
  12. String str = rdr.readLine();
  13. if (str == null) {
  14. arr[0] = '\0'; return;
  15. }
  16. int len = arr.length;
  17. int sLn = str.length();
  18. len = (sLn < len ? sLn : len-1);
  19. str.getChars(0, len, arr, 0);
  20. arr[len] = '\0';
  21. }
  22. public static char Read() throws IOException
  23. {
  24. return (char)rdr.read();
  25. }
  26. public static boolean More() throws IOException
  27. {
  28. return true; // temporary fix until we figure out
  29. // return rdr.ready(); // how to get the same semantics for
  30. } // .NET and the JVM (kjg Sep. 2004)
  31. public static void SkipLn() throws IOException
  32. {
  33. String str = rdr.readLine(); // and discard str
  34. }
  35. } // end of public class StdIn