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

📄 integerreader.java

📁 卡内基梅陇大学的网上教程 ssd3第一单元的源码
💻 JAVA
字号:
package unitOne;

import java.io.*;

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

    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 the method <code>readInteger</code>.
     *
     * @param args  not used.
     */
    public static void main (String[] args) {

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

    /**
     * Reads an integer from the standard output.
     *
     * @return the <code>int</code> value.
     */
    public static int  readInteger()  {

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

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

            } catch (IOException  ioe)  {
                ioe.printStackTrace();

                System.exit(1);     // Terminates the program

            } catch (NumberFormatException  nfe)  {
                stdErr.println("Invalid number format");
            }
            finally{
            	System.err.println("finally");//无论是否有异常,本行语句都会被执行
            }
        }  while (true);
    }
}


⌨️ 快捷键说明

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