Handout #13 CS 106A June 30, 2009 Essential Idioms Although today’s discussion of expressions extends to the detail level, it is important to keep in mind that instincts for programming will be sharpened much more effectively if you pay attention to the more holistic side, concentrating on learning the idioms and patterns that implement particular problem-solving strategies. These idioms give you a considerable amount of power without requiring you to learn too many of their component details. This section summarizes the most important idioms, each of which is covered in more detail in Chapter 2, 3, or 4. The first set of idioms involves getting data in and out of the computer, which provide the necessary support for the input and output phases of a typical programming task. The idioms you use depend on the type of value, as shown in the following table: Type Declaration Input idiom Integer intvar= value;var= readInt("prompt");Floating-point doublevar= value;var= readDouble("prompt");String Stringvar= value;var= readLine("prompt");The following idioms are useful in calculations:
This is the end of the preview.
access the rest of the document.