Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

94 HOUR 7:Using Conditional Tests to Make Decisions


Answers



  1. C.Thebooleanvariable type only can equal trueorfalse, making it
    similar to conditional tests. If you answered A.,I’m sorry,but there’s
    only 17 hours left and we’ve got a lot left to cover. Java doesn’t teach
    itself.

  2. A.defaultstatements are handled if none of the other casestate-
    ments matches the switchvariable.

  3. B.The other answers describe conditioner and a confessional.


Activities
To i m p r ov e y o u r c o n d i t i o n i n g i n t e r m s o f J av a c o n d i t i o n a l s ,review the topics
of this hour with the following activities:

. Add//in front of a breakstatement on one of the lines in the Clock
program to make it a comment,and then compile it and see what hap-
pens when you run it. Try it again with a few more breakstatements
removed.
. Create a short program that stores a value of your choosing from 1 to
100 in an integer variable called grade. Use this gradevariable with a
conditional statement to display a different message for all A,B,C,D,
and F students. Try it first with an ifstatement,and then try it with a
switchstatement.


To s e e J av a p r o g r a m s t h a t i m p l e m e n t t h e s e a c t i v i t i e s ,visit the book’s website
at http://www.java24hours.com.
Free download pdf