Java快读快写

Administrator 18 2025-03-05
Java快速读取模版(算法大量数据输出必备)
import java.io.*;

public class Main {
	    
    public static void main(String[] args) throws Exception {
        // 快读实例化
    	Read r = new Read ();
    	// 快写实例化
    	PrintWriter p = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        /* Code at Here */
    }
    
	// 快读类
    /**
     * Read
     */
    static class Read{
        StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        public String nextLine() throws Exception {
            return br.readLine();
        }

        public double nextDouble() throws Exception {
            st.nextToken();
            return st.nval;
        }

        public int nextInt() throws Exception {
            st.nextToken();
            return (int) st.nval;
        }
    }
}

快读快写的实际运用
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;


public class Main {
    public static void main(String[] args) throws Exception {
        Read r = new Read();
        PrintWriter p = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int a = r.nextInt(), b = r.nextInt(), c = r.nextInt();
        p.println(Math.max(a, Math.max(b, c)));
        p.flush();//手动清空缓冲区,避免部分内容没写满缓冲区导致没有输出完
    }


    static class Read {
        StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public int nextInt() throws Exception {
            st.nextToken();
            return (int) st.nval;
        }


        public double nextDouble() throws Exception {
            st.nextToken();
            return st.nval;
        }
        public String nextLine() throws Exception {
            return br.readLine();
        }
    }
}