Java的快讀模板【輸入提速】

Java的快讀模板,提升輸入效率。

import java.io.*;
import java.util.*;//自定義Read類中需要用到io和util這兩個包,星號*(通配符)表示包中所有的類
import java.math.*;//含大數BigInteger

public class Main {
	public static void main(String [] args) {
		Read cin=new Read(System.in);
		//code...
	}
}

class Read {//自定義快讀 Read
	
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    
    public Read(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        String str = null;
        try {
            str = reader.readLine();
        } catch (IOException e) {
            // TODO 自動生成的 catch 塊
            e.printStackTrace();
        }
        return str;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public Double nextDouble() {
        return Double.parseDouble(next());
    }

    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章