Programming and Problem Solving with Java

(やまだぃちぅ) #1

4


CHAPTER


in our code have always executed in the same or-
der in which we write them. The first statement executes, then the sec-
ond, and so on. One variation on this ordering is the method call, which
executes a separate sequence of statements. But what if we want the
computer to execute the statements in an order other than sequentially?
For example, suppose we want to check the validity of input data and then
perform a calculation ordisplay an error message, but not both. To do so,
we must be able to ask a question and then, based on the answer, choose
one or another course of action.
The ifstatement allows us to execute statements in an order that
differs from their physical order. We can ask a question with this kind of
statement and do one thing if the answer is yes (true) or another if the
answer is no (false). In the first part of this chapter, we deal with asking
questions; in the second part, we examine the ifstatement itself. We
then use the ifstatement to handle multiple event sources, and apply
what we’ve seen in the Case Study.


So far, the statements

1947
The world’s first
transistor is
developed at Bell
Labs

1948
Researchers at the
University of
Manchester develop
the Manchester
Mark I, a computer
with all the main
components of
today’s computers
that can store data
and user programs
in electronic
memory

1949
Jay Forrester refines
magnetic core
memory in his work
on the Whirlwind
computer

1949
John Mauchly
creates the first
high-level
programming
language: Short
Order Code

1950
Alan Turing asks
“Can Machines
Think?” and
outlines criteria for
the Turing Test of
machine intelligence

1951
The UNIVAC
(Universal
Automatic
Computer) I is
completed
Free download pdf