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

📄 integerreaderthrowsexception.java

📁 ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以
💻 JAVA
字号:
import java.io.*;

/**
 * This class provides a method that reads an integer from the
 * standard input.
 *
 * @author author name
 * @version 1.0.0
 */
public class IntegerReaderThrowsException  {

    private static BufferedReader  stdIn =
        new BufferedReader(new  InputStreamReader(System.in));

    private static PrintWriter  stdErr =
        new PrintWriter(System.err, true);

    private static PrintWriter  stdOut =
        new PrintWriter(System.err, true);

    /**
     * Tests method <code>readInteger</code>
     *
     * @param args  not used
     * @throws IOException if error reading from standard input.
     */
    public static void main (String[] args) throws IOException {

        stdOut.println("The value is: " + readInteger());
    }

    /**
     * Reads an integer from the standard output.
     *
     * @return the <code>int</code> value.
     * @throws IOException if error reading from standard input.
     */
    public static int  readInteger() throws IOException {

        do  {
            try  {
                stdErr.print("Enter an integer> ");
                stdErr.flush();

                return Integer.parseInt(stdIn.readLine());

            } catch (NumberFormatException  nfe)  {
                stdErr.println("Invalid number format");
            }
        }  while (true);
    }
}

⌨️ 快捷键说明

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