算法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 ...
随机推荐
- 【PAT】1020. Tree Traversals (25)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...
- Linux 信号
每个进程都需要有个信号处理函数,以捕捉异常信号. 我们在写代码时,有时会有内存非法使用,这种问题一般比较难定位.但是如果有信号处理函数,就可以在捕捉到SEGV信号后打印出详细信息以定位问题. 下面写一 ...
- VM VirtualBox 上安装 CentOs6.4(详细)
在网上下载:CentOS-6.4-i386-bin-DVD1.iso镜像. 这是我在VBox上安装CentOs6.4的过程: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12 ...
- C# 获取字符串中的数字
/// <summary> /// 获取字符串中的数字(不包含小数点) /// </summary> /// <param name="str"> ...
- js时间转换相关
1.json时间格式转换 function ChangeDateFormat(jsondate) { if (!jsondate||jsondate.length < 1) {return &q ...
- Regular Expression--Good parts
匹配URL的正则表达式 <!doctype html><html lang="en"><head> <meta charset=" ...
- Python常用网页字符串处理技巧
首先一些Python字符串处理的简易常用的用法.其他的以后用到再补充. 1.去掉重复空格 s = "hello hello hello" s = ' '.join(s.split( ...
- CSS布局经验谈
1.盒子模型 CSS最具特色也是最本质的可以浓缩成盒子模型. 整个页面可以通过大盒子套小盒子,盒子挨着盒子放,摆成一个页面即可. 盒子即所谓的块元素,只有块元素才有宽和高,有了宽和高才能使盒子挨着盒子 ...
- Myeclipse如何整合tomcat
.在本机上安装MyEclipse和Tomcat 5软件程序 2.运行MyEclipse,设置与Tomcat 5服务器的连接,如下图所示: 选择Window--->Preferences,点击进入 ...
- 手游产品经理初探(六)粗糙的logo会给产品致命一击
假设你的游戏产品从logo的设计開始就不注重细节的话,那么你的产品将不会走多远! 我们把图片放大看: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1 ...