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

📄 consolereader.java

📁 ConsoleReader.java,download it quickly,thanks!
💻 JAVA
字号:
package com.common.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 * A class to read strings and numbers from an input stream. This class is
 * suitable for beginning Java programmers. It constructs the necessary buffered
 * reader, handles I/O exceptions, and converts strings to numbers.
 */

public class ConsoleReader
{
	/**
	 * Constructs a console reader from an input stream such as System.in
	 * 
	 * @param inStream
	 * an input stream
	 */
	public ConsoleReader(InputStream inStream)
	{
		reader = new BufferedReader(new InputStreamReader(inStream));
	}

	/**
	 * Reads a line of input and converts it into an integer. The input line
	 * must contain nothing but an integer. Not even added white space is
	 * allowed.
	 * 
	 * @return the integer that the user typed
	 */
	public int readInt()
	{
		String inputString = readLine();
		int n = Integer.parseInt(inputString);
		return n;
	}

	/**
	 * Reads a line of input and converts it into a floating- point number. The
	 * input line must contain nothing but a nunber. Not even added white space
	 * is allowed.
	 * 
	 * @return the number that the user typed
	 */
	public double readDouble()
	{
		String inputString = readLine();
		double x = Double.parseDouble(inputString);
		return x;
	}

	/**
	 * Reads a line of input. In the (unlikely) event of an IOException, the
	 * program terminates.
	 * 
	 * @return the line of input that the user typed, null at the end of input
	 */
	public String readLine()
	{
		String inputLine = "";

		try
		{
			inputLine = reader.readLine();
		} catch (IOException e)
		{
			System.out.println(e);
			System.exit(1);
		}

		return inputLine;
	}

	private BufferedReader reader;
}

⌨️ 快捷键说明

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