Skip to content

Instantly share code, notes, and snippets.

@paullewallencom
Last active July 26, 2018 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paullewallencom/aa27b60080196880ced3c1713ddbd7f7 to your computer and use it in GitHub Desktop.
Save paullewallencom/aa27b60080196880ced3c1713ddbd7f7 to your computer and use it in GitHub Desktop.
Writes Data of Various Types to Standard Output
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
public final class StdOut
{
private static final String CHARSET_NAME = "UTF-8";
private static final Locale LOCALE = Locale.US;
private static PrintWriter out;
static
{
try
{
out = new PrintWriter( new OutputStreamWriter( System.out, CHARSET_NAME ), true );
} catch ( UnsupportedEncodingException e ) {
System.out.println( e );
}
}
private StdOut() { }
@Deprecated
public static void close() { out.close(); }
public static void println() { out.println(); }
public static void println( Object x ) { out.println( x ); }
public static void println( boolean x ) { out.println( x ); }
public static void println( char x ) { out.println( x ); }
public static void println( double x ) { out.println( x ); }
public static void println( float x ) { out.println( x ); }
public static void println( int x ) { out.println( x ); }
public static void println( long x ) { out.println( x ); }
public static void println( short x ) { out.println( x ); }
public static void println( byte x ) { out.println( x ); }
public static void print() { out.flush(); }
public static void print( Object x )
{
out.print( x );
out.flush();
}
public static void print( boolean x )
{
out.print( x );
out.flush();
}
public static void print( char x )
{
out.print( x );
out.flush();
}
public static void print( double x )
{
out.print( x );
out.flush();
}
public static void print( float x )
{
out.print( x );
out.flush();
}
public static void print( int x )
{
out.print( x );
out.flush();
}
public static void print( long x )
{
out.print( x );
out.flush();
}
public static void print( short x )
{
out.print( x );
out.flush();
}
public static void print( byte x )
{
out.print( x );
out.flush();
}
public static void printf( String format, Object... args )
{
out.printf( LOCALE, format, args );
out.flush();
}
public static void printf( Locale locale, String format, Object... args )
{
out.printf( locale, format, args );
out.flush();
}
public static void main( String[] args )
{
StdOut.println( "Test" );
StdOut.println( 17 );
StdOut.println( true );
StdOut.printf( "%.6f\n", 1.0/7.0 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment