?? integerreader.java
字號:
/*!Begin Snippet:file*/
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");
}
} while (true);
}
}
/*!End Snippet:file*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -