29. Formatted Output

All the news that’s fit to print.

Adolph S. Ochs

What mad pursuit? What struggle to escape?

John Keats

Remove not the landmark on the boundary of the fields.

Amenehope

Objectives

In this chapter you will learn:

  • To understand input and output streams.

  • To use printf formatting.

  • To print with field widths and precisions.

  • To use formatting flags in the printf format string.

  • To print with an argument index.

  • To output literals and escape sequences.

  • To format output with class Formatter.

Outline

29.1 Introduction

29.2 Streams

29.3 Formatting Output with printf

29.4 Printing Integers

29.5 Printing Floating-Point Numbers

29.6

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.