算法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 ...
随机推荐
- halcon,C# 学习
Halcon学习之一:查询图像参数 1.get_grayval ( Image : : Row, Column : Grayval ) 计算Image图像中坐标为(Row,Column)的点的灰度值G ...
- Struts2 高危漏洞补丁版本为: Struts 2.3.15.1
Struts2 昨天爆出高危漏洞,黑客利用这个漏洞可以执行任意命令(包括恶意的jsp代码),轻松绕过您的验证系统,登陆您的网站后台,使您的网站后台密码形同虚设!! 目前Struts2官方已经发布了一个 ...
- C:内存分配、内存中五大区
1.内存的划分 (从高到低依次是: 栈区 . 堆区 .全局静态区 . 常量区 . 代码区 )栈区是系统自动回收,堆区是我们手动回收 2. 栈区 在函数内部定义的局部变量和数组.都存放在栈区, ...
- Flex data
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- 10.关联(Association)
关联关系是类与类之间最常用的一种关系,它是一种结构化关系,用于表示一类对象与另一类对象之间有联系.它体现的是两个类.或者类与接口之间语义级别的一种强依赖关系,比如我和我的朋友.这种关系比依赖更强.不存 ...
- Ext.form.ComboBox 后台取值 动态加载 ext5.0.0
我用的extjs是5.0.0版本的. 请注意:如果这里没有的combobox相关内容,这里一定有. 开始的时候keyup事件取到的数据就是放不到ComboBox中,放全局变量也不好用.最后大神出手帮忙 ...
- 用java写一个web服务器
一.超文本传输协议 Web服务器和浏览器通过HTTP协议在Internet上发送和接收消息.HTTP协议是一种请求-应答式的协议——客户端发送一个请求,服务器返回该请求的应答.HTTP协议使用可靠的T ...
- VC++ 网络编程总结(二)
2.基本的Windows Socket API编程 需要在程序中添加下面的包含语句:#include <winsock2.h> #pragma comment( lib, " ...
- 数据结构复习:直接插入排序与二分插入排序的C++实现
1.直接插入排序 直接插入排序的过程可以理解为一个固定长度的数组被分为两个集合,即已排序集合和未排序. 开始时已排序集合为空,而未排序集合即为整个数组.当排序开始后插入一个对象,已排序集合元素数目加1 ...
- Python int与string之间的转化
string-->int 1.10进制string转化为int int('12') 2.16进制string转化为int int('12', 16) int-->string 1.int转 ...