Java Reference
In-Depth Information
Homework Assignments
Start
1. In the flowchart in Figure A-22, what are the values of I and J at the
instant just after the statement J = J + 1 is executed for the fifth time?
What are the values of I and J after the statement I = I + 2 is executed the
tenth time? (A statement such as J = J + 1 is valid and is read
as the new value of J equals the old value of J plus one or, equivalently, the
value of J is to be replaced by the value of J plus one .)
2. Consider the section of a flowchart shown in Figure A-23. It assumes
that an absent-minded person is going to work. This individual usually
has the car keys but occasionally forgets them. Does the flowchart section
in Figure A-23 incorporate the most efficient method of representing
the actions to be taken? If not, redraw the flowchart portion given in
Figure A-23.
I = 1
J = 4
X
J = J + 1
I = I + 2
X
Get into Car
FIGURE A-22
No
Have
Keys
Get Out of Car
and Get Keys
Start
A
Yes
I = 1
J = 4
Start Engine
FIGURE A-23
J = J + 1
3. In the flowchart shown in Figure A-24, what values of I and J are printed
when the output symbol is executed for the fiftieth time?
4. An opaque urn contains three diamonds, four rubies, and two pearls.
Construct a flowchart that describes the following events: Take a gem
from the urn. If it is a diamond, lay it aside. If it is not a diamond, return
it to the urn. Continue in this fashion until all the diamonds have been
removed. After all the diamonds have been removed, repeat the same
procedure until all the rubies have been removed. After all the rubies
have been removed, continue in the same fashion until all the pearls have
been removed.
5. In the flowchart represented by Figure A-25, what are the values of I and
J at the instant the terminal symbol with the word End is reached?
I = I + 2
Print
I, J
A
FIGURE A-24
 
Search WWH ::




Custom Search