How to Print Fast Output in Competitive Programming using Java?
In Competitive programming, most of the students use C++ as their primary language as it is faster than the other languages(e.g Java, Python) but for a student/professional who use Java as his/her primary language taking Input from input streams and printing fast output is the main difficulty faced during contests on competitive platforms(eg. CodeChef, CodeForces, Spoj, etc).
In this article, there defined the fastest method to print O/P using Java (Mainly in Competitive Programming).
BufferedWriter Class: It writes text to a character-output stream, buffering characters to provide for the efficient writing of single characters, arrays, and strings. It makes the performance fast.
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
Methods of BufferedWriter:
- write(): writes a single character to the internal buffer of the writer.
- write(char array): writes the characters from the specified array to the writer.
- write(String data): writes the specified string to the writer.
- flush(): used to clear the internal buffer.
- close(): used to close the buffered writer.
Below is the implementation of the problem statement:
Geeks For Geeks