Hello,
Here I am sharing my template for competitive coding in java with fast I/O.
Ps:
- You don’t always have to use this Reader class. I use it only when my own reader class fails, I am sharing it below as well.
- You can also use PrintWriter instead of BufferedWriter.
import java.io.*; import java.util.*; public class Template { static PrintWriter out=new PrintWriter((System.out)); public static void main(String args[])throws IOException { Reader sc=new Reader(); int t=sc.nextInt(); while(t-->0) { solve(); } out.close(); } public static void solve() { } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next() { while(!st.hasMoreTokens()) { try { st=new StringTokenizer(br.readLine()); } catch(Exception e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return br.readLine(); } catch(Exception e) { e.printStackTrace(); } return null; } public boolean hasNext() { String next=null; try { next=br.readLine(); } catch(Exception e) { } if(next==null) { return false; } st=new StringTokenizer(next); return true; } } }