⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:
import java.io.*;/** The <B>Console</B> class provides methods that allow easy reading of the basic    data types <TT>double</TT>, <TT>int</TT>, and <TT>String</TT> from standard input.    <I>Must be placed in the same directory as the source code using it.</I><P>     <B>Usage Example:</B>     <PRE>     System.out.println("Enter a double number: ");     double x = Console.readDouble();     System.out.println("You have entered: " + x);      </PRE> */public class Console{/** Reads a single double from the keyboard. Stops execution in case oferror.      @return double   */   public static double readDouble()   {  try      {  return Double.valueOf(readString().trim()).doubleValue(); }      catch(NumberFormatException ne)      {  System.err.println("Console.readDouble: Not a double...");         System.exit(-1);         return 0.0;      }   }   /** Reads a single int from the keyboard. Stops execution in case of error.       @return int   */   public static int readInt()   {  try      {  return Integer.valueOf(readString().trim()).intValue(); }      catch(NumberFormatException ne)      {  System.err.println("Console.readInt: Not an integer...");         System.exit(-1);         return -1;      }   }   /** Reads a String from the keyboard until RETURN or ENTER key is pressed.       @return String  */   public static String readString()   { String string = new String();     BufferedReader in=new BufferedReader(new InputStreamReader(System.in));      try      {  string = in.readLine(); }      catch(IOException e)      { System.out.println("Console.readString: Unknown error...");        System.exit(-1);      }      return string;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -