{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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 RIMITIVE T YPES , S TRINGS , AND I NTERACTIVE I/O 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
Image of page 1

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

View Full Document Right Arrow Icon
P RIMITIVE T YPES , S TRINGS , AND I NTERACTIVE I/O P RIMITIVE T YPES , S TRINGS , AND I NTERACTIVE I/O 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern