Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
Java Language EssentialsDownload tutorial zip fileEmail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
Exercises
  


4. Using Java If-Statements: Tasks page 11 of 31


For this exercise you will define some variables representing temperatures (in Fahrenheit) and print out whether or not a termperature 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.].

For more help with exercises, see About The Exercises

Prerequisites
  • None.

Tasks

  • Task 1

    Define local variables hot=100, cold=50, and temp=55. Print out the value of temp.

  • Task 2

    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".

  • Task 3

    Use an if-statement to test for the temperature being in between cold and hot. If it is, print "warm." Else, print "extreme temperature."

Help for each of these tasks can be found on the next page.


copyright 1996-2000 Magelang Institute dba jGuru


Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
PrivacyLegalContact