算法java(Robert Sedgewick)基本API-StdOut.java
/*************************************************************************
* Compilation: javac StdOut.java
* Execution: java StdOut
*
* Writes data of various types to standard output.
*
*************************************************************************/ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Locale; /**
* <i>Standard output</i>. This class provides methods for writing strings
* and numbers to standard output.
* <p>
* For additional documentation, see <a href="http://introcs.cs.princeton.edu/15inout">Section 1.5</a> of
* <i>Introduction to Programming in Java: An Interdisciplinary Approach</i> by Robert Sedgewick and Kevin Wayne.
*
* @author Robert Sedgewick
* @author Kevin Wayne
*/
public final class StdOut { // force Unicode UTF-8 encoding; otherwise it's system dependent
private static final String CHARSET_NAME = "UTF-8"; // assume language = English, country = US for consistency with StdIn
private static final Locale LOCALE = Locale.US; // send output here
private static PrintWriter out; // this is called before invoking any methods
static {
try {
out = new PrintWriter(new OutputStreamWriter(System.out, CHARSET_NAME), true);
}
catch (UnsupportedEncodingException e) { System.out.println(e); }
} // don't instantiate
private StdOut() { } // close the output stream (not required)
/**
* Close standard output.
*/
public static void close() {
out.close();
} /**
* Terminate the current line by printing the line separator string.
*/
public static void println() {
out.println();
} /**
* Print an object to standard output and then terminate the line.
*/
public static void println(Object x) {
out.println(x);
} /**
* Print a boolean to standard output and then terminate the line.
*/
public static void println(boolean x) {
out.println(x);
} /**
* Print a char to standard output and then terminate the line.
*/
public static void println(char x) {
out.println(x);
} /**
* Print a double to standard output and then terminate the line.
*/
public static void println(double x) {
out.println(x);
} /**
* Print a float to standard output and then terminate the line.
*/
public static void println(float x) {
out.println(x);
} /**
* Print an int to standard output and then terminate the line.
*/
public static void println(int x) {
out.println(x);
} /**
* Print a long to standard output and then terminate the line.
*/
public static void println(long x) {
out.println(x);
} /**
* Print a short to standard output and then terminate the line.
*/
public static void println(short x) {
out.println(x);
} /**
* Print a byte to standard output and then terminate the line.
*/
public static void println(byte x) {
out.println(x);
} /**
* Flush standard output.
*/
public static void print() {
out.flush();
} /**
* Print an Object to standard output and flush standard output.
*/
public static void print(Object x) {
out.print(x);
out.flush();
} /**
* Print a boolean to standard output and flush standard output.
*/
public static void print(boolean x) {
out.print(x);
out.flush();
} /**
* Print a char to standard output and flush standard output.
*/
public static void print(char x) {
out.print(x);
out.flush();
} /**
* Print a double to standard output and flush standard output.
*/
public static void print(double x) {
out.print(x);
out.flush();
} /**
* Print a float to standard output and flush standard output.
*/
public static void print(float x) {
out.print(x);
out.flush();
} /**
* Print an int to standard output and flush standard output.
*/
public static void print(int x) {
out.print(x);
out.flush();
} /**
* Print a long to standard output and flush standard output.
*/
public static void print(long x) {
out.print(x);
out.flush();
} /**
* Print a short to standard output and flush standard output.
*/
public static void print(short x) {
out.print(x);
out.flush();
} /**
* Print a byte to standard output and flush standard output.
*/
public static void print(byte x) {
out.print(x);
out.flush();
} /**
* Print a formatted string to standard output using the specified
* format string and arguments, and flush standard output.
*/
public static void printf(String format, Object... args) {
out.printf(LOCALE, format, args);
out.flush();
} /**
* Print a formatted string to standard output using the specified
* locale, format string, and arguments, and flush standard output.
*/
public static void printf(Locale locale, String format, Object... args) {
out.printf(locale, format, args);
out.flush();
} // This method is just here to test the class
public static void main(String[] args) { // write to stdout
StdOut.println("Test");
StdOut.println(17);
StdOut.println(true);
StdOut.printf("%.6f\n", 1.0/7.0);
} }
算法java(Robert Sedgewick)基本API-StdOut.java的更多相关文章
- 算法第四版 coursera公开课 普林斯顿算法 ⅠⅡ部分 Robert Sedgewick主讲《Algorithms》
这是我在网上找到的资源,下载之后上传到我的百度网盘了. 包含两部分:1:算法视频的种子 2:字幕 下载之后,请用迅雷播放器打开,因为迅雷可以直接在线搜索字幕. 如果以下链接失效,请在下边留言,我再更新 ...
- [转载]Java 8 日期&时间 API
Java 8 日期和时间 声明 本文转自http://www.journaldev.com/2800/java-8-date-localdate-localdatetime-instant,以mark ...
- Java基础知识强化99:Java 常见异常及趣味解释
常见 Java 异常解释:(译者注:非技术角度分析.阅读有风险,理解需谨慎:) 1. java.langjava.lang软件包是java语言的核心部分,它提供了java中的基础类. java.lan ...
- 配置算法(第4版)的Java编译环境
1. 下载 1.1 JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html选择“Windows x64 180.5 ...
- Java高并发秒杀API之Service层
Java高并发秒杀API之Service层 第1章 秒杀业务接口设计与实现 1.1service层开发之前的说明 开始Service层的编码之前,我们首先需要进行Dao层编码之后的思考:在Dao层我们 ...
- atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js
atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js 1. 两个方法:: bat vs mysqldump(推荐) vs lang ...
- 03.Java多线程并发库API使用2
1.多个线程之间共享数据的方式探讨 1.如果每个线程执行的代码相同,可以使用同一个Runnable对象,这个Runnable对象中有那个共享数据,例如,买票系统就可以这么做. 2.如果每个线程执行的代 ...
- paip.文件读写api php java python总结.txt
paip.文件读写api php java python总结.txt 一.多种方式读文件内容. 1.按字节读取文件内容 以字节为单位读取文件,常用于读二进制文件,如图片.声音.影像等文件. ...
- Java 8 Date Time API Example Tutorial – LocalDate, Instant, LocalDateTime, Parse and Format
参考 Java 8 Date and Time API is one of the most sought after change for developers. Java has been mis ...
随机推荐
- 利用HTML5开发Android(4)---HTML5本地存储之Web Storage
Web Storage是HTML5引入的一个非常重要的功能,可以在客户端本地存储数据,类似HTML4的cookie,但可实现功能要比cookie强大的多,cookie大小被限制在4KB,Web Sto ...
- Android读取assets目录下的资源
1.获取资源的输入流 资源文件 sample.txt 位于 $PROJECT_HOME/assets/ 目录下,可以在 Activity 中通过 Context.getAssets().open(“s ...
- Hadoop伪分布配置与基于Eclipse开发环境搭建
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- TMS3705A PCF7991AT 线路图
- 数据结构之hash表
哈希表是种数据结构,它可以提供快速的插入操作和查找操作.hash定义了一种将字符组成的字符串转换为固定长度(一般是更短长度)的数值或索引值的方法,称为散列法,也叫哈希法.由于通过更短的哈希值比用原始值 ...
- 【M31】让函数根据一个以上的对象类型来决定如何虚化
1.考虑下面的问题,游戏软件中有角色A,B,角色又可以细化为A1,A2,A3:B1,B2,B3,两类角色之间相互攻击.即A1可以攻击B1,B2,B3,B1可以攻击A1,A2,A3.C++的多态,只根据 ...
- jquery动态创建form并提交到.ashx文件处理
有时候在写web 应用的时候,需要临时动态构造一个form 并提交,form 里面的参数以及action,以及是post请求还是get请求,甚至form 的样式都是可以指定的,用原生的java ...
- POJ 2376 Cleaning Shifts 贪心
Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...
- GEOS库 介绍 (转)
http://wiki.woodpecker.org.cn/moin/lilin/geos-introduce 介绍 GEOS是一个集合形状的拓扑关系操作实用库(可能这么说不太准确),简单得说,就是判 ...
- 因为改 UOM conversion 导致库存数量和財务上的数据错误
轻易改变 UOM conversion 会导致库存数量混乱, 也会造成財务上的数据错误. 我们这里做一个 case 来详细分析一下. 1. 開始 Carton 和 Each 的比例是 1 : 1. 2 ...