CH02.FM - CHAPTER 2 PRIMITIVE TYPES, STRINGS, AND...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
51 • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • C HAPTER 2 P RIMITIVE T YPES , S TRINGS , AND I NTERACTIVE I/O P T I 2.1 P RIMITIVE T YPES AND E XPRESSIONS 53 Variables 53 Primitive Types 57 Assignment Statements 58 Specialized Assignment Operators 60 Simple Input and Output 61 Number Constants 62 Assignment Compatibilities 63 Type Casting 64 Java Tip Type Casting a Character to an Integer 66 Programming Tip Initialize Variables 67 Gotcha Imprecision in Floating-Point Numbers 67 Arithmetic Operators 69 Parentheses and Precedence Rules 71 Case Study Vending Machine Change 73 Increment and Decrement Operators 77 More About Increment and Decrement Operators 78 2.2 T HE C LASS String 79 String Constants and Variables 80 Concatenation of Strings 80 String Methods 81 String Processing 85 Escape Characters 86 The Unicode Character Set 88 2.3 K EYBOARD AND S CREEN I/O 89 Screen Output 89 Input Using SavitchIn 91 More Input Methods 94 Gotcha readInt and readDouble 96 Programming Tip Echo Input 96 2.4 D OCUMENTATION AND S TYLE 98 Programming Tip Use Meaningful Names for Variables 98 Documentation and Comments 99 Indenting 100 Named Constants 101 2.5 W INDOWING I/O WITH JO PTION P ANE (Optional) 105 A Simple Windowing Program 106 Gotcha Users Who Enter Inappropriate Input 110 Gotcha Forgetting System.exit(0); 112 Gotcha Outputting Just a Number 113 Inputting Other Numeric Types 114 Java Tip Multi-Line Output Windows 115 Programming Example Another Program with I/O Windows 115 Chapter Summary 116 Answers to Self-Test Questions 119 Programming Exercises 123
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P RIMITIVE T YPES , S TRINGS , AND I NTERACTIVE I/O P T I 2 • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • I n this chapter, we explain enough about the Java language to allow you to write simple Java programs. You do not need to have done any programming to under- stand this chapter. On the other hand, if you are already familiar with some other programming language, such as C, C++, Pascal, BASIC, or FORTRAN, then much of what is in Section 2.1 will already be familiar to you. However, even if you know the concepts, you should learn the Java way of expressing these concepts.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2010 for the course CS 5503 taught by Professor Kaylor during the Spring '10 term at University of West Alabama-Livingston.

Page1 / 76

CH02.FM - CHAPTER 2 PRIMITIVE TYPES, STRINGS, AND...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online