RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lect02c-soln-pizzaArea
pizzaArea with a local variables

  /** pizzaArea
   *  Given a nonnegative diameter diam (in inches), return the surface
   *  area of the pizza top (in square inches).
   *  Accurate to within 1%.
   *    (Test cases omitted to fit on one screen, in lectures.)
   */
  double pizzaArea( double diam ) {
    double radius;
    radius = diam/2;
    return 3.14 * radius * radius;
    }
Here, radius is a local variable. It is used as a temporary name; the name is only meanginful when somebody calls pizzaArea, and it goes away when pizzaArea returns its answer. Moreover, radius can only be used between the curly-braces which enclose the declaration.

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2008, Ian Barland, Radford University
Last modified 2008.Jan.24 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme