Advertisement
Evang12

Java Fast IO

Jun 26th, 2022
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5.     static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  6.     static StringTokenizer st;
  7.     static PrintWriter pw = new PrintWriter(System.out);
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.         int n = readInt();
  11.         String s = next();  // reads a string (not necessarily an entire line!)
  12.         String entireLine = readLine();
  13.         double myDouble = readDouble();
  14.  
  15.         pw.println("Use PrintWriter -- it's faster!");
  16.         pw.print("PrintWriter is shorter to write (compared to System.out.println)\n");
  17.         pw.println("But be careful when using PrintWriter in interactive problems " +
  18.             "use pw.flush() to make sure pw prints before the next input!");
  19.         pw.flush();
  20.  
  21.         pw.close();  // always write this line before ending the program!!
  22.     }
  23.  
  24.     static String readLine() throws IOException {
  25.         return br.readLine().trim();
  26.     }
  27.     static String next() throws IOException {
  28.         while(st == null || !st.hasMoreTokens())
  29.             st = new StringTokenizer(readLine());
  30.         return st.nextToken();
  31.     }
  32.     static int readInt() throws IOException {
  33.         return Integer.parseInt(next());
  34.     }
  35.     static double readDouble() throws IOException {
  36.         return Double.parseDouble(next());
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement