Think Java - How to Think Like a Computer Scientist (2016).pdf

(5369 KB) Pobierz
Think
Java
HOW TO THINK LIKE A COMPUTER SCIENTIST
Allen B. Downey & Chris Mayfield
How to Think Like a Computer Scientist
Think Java
Allen B. Downey and Chris Mayfield
Beijing
Boston Farnham Sebastopol
Tokyo
Think Java
by Allen B. Downey and Chris Mayfield
Copyright © 2016 Allen B. Downey and Chris Mayfield. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor:
Brian Foster
Production Editor:
Kristen Brown
Copyeditor:
Charles Roumeliotis
Proofreader:
Christina Edwards
May 2016:
First Edition
Indexers:
Allen B. Downey and Chris Mayfield
Interior Designer:
David Futato
Cover Designer:
Karen Montgomery
Illustrator:
Rebecca Demarest
Revision History for the First Edition
2016-05-06:
First Release
See
http://oreilly.com/catalog/errata.csp?isbn=9781491929568
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Think Java,
the cover image, and
related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
Think Java
is available under the Creative Commons Attribution-NonCommercial 3.0 Unported License.
The author maintains an online version at
http://greenteapress.com/wp/think-java/.
978-1-491-92956-8
[LSI]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1.
The Way of the Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is Programming?
What Is Computer Science?
Programming Languages
The Hello World Program
Displaying Strings
Escape Sequences
Formatting Code
Debugging Code
Vocabulary
Exercises
Declaring Variables
Assignment
State Diagrams
Printing Variables
Arithmetic Operators
Floating-Point Numbers
Rounding Errors
Operators for Strings
Composition
Types of Errors
Vocabulary
Exercises
1
2
3
4
5
6
7
8
8
10
13
14
15
16
16
17
19
19
21
21
24
25
2.
Variables and Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
iii
Zgłoś jeśli naruszono regulamin