输入输出封装的BufferReader模板


import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    static final int N = (int) (1e5 + 10), INF = 0x3f3f3f3f;
    // static int arr[] = new int[N];
    // static int arr[][] = new int[N][N];
    // static char g[][] = new char[N][N];
    // static boolean st[][] = new boolean[N][N];
    static int n, m, t;
    static int res, ans;

    static void solve() {
        // t = sc.nextInt();
        // while (t-- > 0) {
        while (sc.hasNext()) {
            

            out.flush();
        }
        out.flush();
    }

    static void solveCom() {
        solve();
        out.flush();
    }

    public static void main(String[] args) {
        solveCom();

        out.flush(); // 最后清空并关闭输出流
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out); // 输出流, 输出完之后记得用 out.flush() 清空一下缓存区
    static Reader sc = new Reader();

    static class Reader { // 封装快速读取类的方法(基于Scanner的方法来写)
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        boolean hasNext() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = br.readLine();
                    if (line == null) return false;
                    st = new StringTokenizer(line);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

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

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

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

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


全部评论

相关推荐

11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
10-14 23:01
已编辑
中国地质大学(武汉) Java
CUG芝士圈:虽然是网上的项目,但最好还是包装一下,然后现在大部分公司都在忙校招,十月底、十一月初会好找一些。最后,boss才沟通100家,别焦虑,我去年暑假找第一段实习的时候沟通了500➕才有面试,校友加油
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务