CIS 270—Application Development II Chapter 28—Formatted Output.

Slides:



Advertisements
Similar presentations
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Advertisements

Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
The Print Formatting Statement … named printf. 2 Introduction to printf statements print and println statements don’t allow us to easily format output.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
Printing. printf: formatted printing So far we have just been copying stuff from standard-in, files, pipes, etc to the screen or another file. Say I have.
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
11 Chapter 3 DECISION STRUCTURES CONT’D. 22 FORMATTING FLOATING-POINT VALUES WITH THE DecimalFormat CLASS We can use the DecimalFormat class to control.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
CIS 270—Application Development II Chapter 14—Files and Streams.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Formatting and Parsing. Slide 2 Introduction Two core topics Parsing - Converting strings to other types (numbers, dates, …) Formatting Converting those.
Chapter 2 – Continued Basic Elements of Java. Chapter Objectives Type Conversion String Class Commonly Used String Methods Parsing Numeric Strings Commonly.
Chapter 2: Java Fundamentals Type conversion,String.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
1 Pertemuan 4 Fungsi-Fungsi Bahasa C Matakuliah: T0016/Algoritma dan Pemrograman Tahun: 2005 Versi: versi 2.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Dale Roberts Basic I/O (Chap. 9) CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
Formatting Output. Formatting features of printf System.out.printf can perform the following Rounding floating-point values Aligning properly a column.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 2- Using Java Built-in Classes Topic 2.6 Reading Input with java.io Produced by Harvey.
CS 1704 Introduction to Data Structures and Software Engineering.
Simple Console Output. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
Input and Output The system console. In the beginning … When computers were relatively expensive and rare, most users interacted with a terminal –CRT.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
28 Formatted Output.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
Chapter 9 C Formatted Input/Output
Objectives You should be able to describe: Interactive Keyboard Input
University of Central Florida COP 3330 Object Oriented Programming
TMF1414 Introduction to Programming
Introduction to C CSE 2031 Fall /3/ :33 AM.
OUTPUT STATEMENTS GC 201.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Chapter 08- printf and scanf
Formatting Output.
System.out.println for console output
Lecture 13 Input/Output Files.
Chapter 9 - Formatted Input/Output
Introduction to Java Applications
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Presentation transcript:

CIS 270—Application Development II Chapter 28—Formatted Output

Introduction Method printf formats and outputs data to the standard output stream— _____________. Class Formatter does likewise to a specified destination, such as a string or a file output stream.

Streams A stream is a sequence of _______. For input, streams flow from a device to main memory. For output, streams flow from main memory to a device. Three automatic Java streams: System.in —connected to the keyboard System.out —connected to the screen System.err —connected to the screen, for error messages

Formatting Output with printf printf( format-string, argument-list ); format-string describes the output format can contain fixed text and format ___________ a format specifier, such as f, is a placeholder for a value a format specifier begins with % and is followed by a conversion character, such as %f optional formatting information is specified between the % and the conversion character, such as %.2f The argument-list contains literals or _________ that correspond in number and type to the conversion characters in the format-string. The argument index (such as 1$ ) can specify argument to which formatting will apply: %1$.2f

Printing Integers An integer is a + or – whole number with no decimal point. Integral conversion characters d for decimal (base 10) integers (e.g., 26) o for _______ (base 8) integers (e.g., 26  32) x or X for hexidecimal (base 16) integers (e.g. 26  1A) The printf method Format: printf( format-string, argument-list ); Example: int aNumber = 26; System.out.printf( “%d\n”, aNumber);

Printing Floating-Point Numbers A floating-point value contains a decimal point. Floating-point conversion characters e or E for ____________ notation f for for floating-point, decimal format g or G for floating-point or exponential format depending on the magnitude of the value ( e for 10 7 ) a or A for floating-point in hexidecimal format Examples System.out.printf( “%e\n”, ); Result: e+07 System.out.printf( “%f\n”, ); Result:

Printing Strings and Characters Character and string conversion characters c or C for characters (lower and upper case, respectively) s or S for strings (lower and upper case, respectively) Using s can convert an _________ object to a string. Formatting characters cannot convert a string to a character.

Printing Dates and Times 1 The conversion characters t or T can print dates and times. The conversion ________ character specifies formats. Examples: %tc for complete date and time %tF for year-month-date format %tr for hour:minute:second AM|PM format %tA for the full day of the week (e.g., Wednesday) %tp for morning or afternoon marker in lower case (pm)

Printing Dates and Times 2 Application for dates and times Calendar today = Calendar.getInstance(); System.out.printf(“%1$tA, %1$tB %1$td, %1$tY\n”, today); Result: Wednesday, August 03, 2005

Printing with Field Widths and Precision An integer right of % is the maximum field width ( + for right justification, - for left justification) A. to the right of %, followed by a positive integer, is the number of decimal places to be displayed. Example: printf( “%9.3f”, ); Right justifies ( +, implied) using a __________ field width of 9 with 3 decimal places. Result:

Using Flags A flag is placed just to the right of the % Flags - to left justify + to display a + for positive values and – for negative values 0 to pad a field with leading zeros, to use the locale-specific thousands separator ( to enclose negative numbers in parentheses

Class Formatter System.out.printf() sends output to the standard output stream (screen). The class Formatter (in package ___________ ) allows sending formatted output to a specified destination. Example Formatter formatter = new Formatter(); formatter.format(“%d = %#o = %#X, 10, 10, 10); JOptionPane.showMessageDialog(null, formatter.toString()); Also, String x = String.format (“%d = %#o = %#X, 10, 10, 10);