ch04 - Before writing a program to solve a problem have a...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full Document Right Arrow Icon
Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building blocks that are available and employ proven program-construction techniques. This chapter introduces The if , if else and while statements Compound assignment, increment and decrement operators Portability of Java’s primitive types
Background image of page 2
Any computing problem can be solved by executing a series of actions in a specific order. An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute The “rise-and-shine algorithm” followed by one executive for getting out of bed and going to work: (1) Get out of bed; (2) take off pajamas; (3) take a shower; (4) get dressed; (5) eat breakfast; (6) carpool to work. Suppose that the same steps are performed in a slightly different order: (1) Get out of bed; (2) take off pajamas; (3) get dressed; (4) take a shower; (5) eat breakfast; (6) carpool to work. Specifying the order in which statements (actions) execute in a program is called program control .
Background image of page 3

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

View Full Document Right Arrow Icon
Pseudocode is an informal language that helps you develop algorithms without having to worry about the strict details of Java language syntax. Particularly useful for developing algorithms that will be converted to structured portions of Java programs. Similar to everyday English. Helps you “think out” a program before attempting to write it in a programming language, such as Java. You can type pseudocode conveniently, using any text-editor program. Carefully prepared pseudocode can easily be converted to a corresponding Java program. Pseudocode normally describes only statements representing the actions that occur after you convert a program from pseudocode to Java and the program is run on a computer. e.g., input, output or calculations.
Background image of page 4
Sequence structure Built into Java. Unless directed otherwise, the computer executes Java statements one after the other in the order in which they’re written. Java lets you have as many actions as you want in a sequence structure. Anywhere a single action may be placed, we may place several actions in sequence.
Background image of page 5

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

View Full Document Right Arrow Icon
Three types of selection statements . if statement: Performs an action, if a condition is true; skips it, if false. Single-selection statement —selects or ignores a single action (or group of actions). if else statement: Performs an action if a condition is true and performs a different action if the condition is false. Double-selection statement —selects between two different actions (or groups of actions). switch
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 54

ch04 - Before writing a program to solve a problem have a...

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

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