by 
[Help |
API Docs |
Short Course|
Exercises]
For this exercise you will define some variables representing temperatures (in Fahrenheit) and print out whether or not a temperature is hot, cold, warm, or extreme.
[If you are using IBM's VisualAge for Java for this exercise, then use the scrapbook to type and test your code (without a main method etc...), thus, avoiding the need to fill in the skeleton code, compile, and run from the command line.].
Prerequisites
Skeleton Code
Tasks
Define local variables hot=100, cold=50, and temp=55. Print out the value of temp.
Use an if statement to test for the temperature being exactly cold. If true, print "cold." If false (use an else clause), test to see if temp is exactly hot. If so, print "hot".
Use an if statement to test for the temperature being in between cold and hot. If it is, print "warm." Else, print "extreme temperature."
Where help exists, the task numbers above are linked to the step-by-step help page.
Solution Source
Demonstration
If you execute Ifs from a command line, the output should be similar to the following:
temp is 55 warm
Copyright 1996-2000 jGuru.com. All Rights Reserved.
|
|