Split Temporary Variable

From CSSEMediaWiki
Revision as of 07:12, 24 November 2010 by Ebybymic (Talk | contribs)
Jump to: navigation, search

This is when you have create a temporary variable that you use all the way through a method.<br>

   foo() {<br>
       int temp = 2 * (height + width);<br>
       System.out.print(temp);<br>
       temp = height * width;<br>
       System.out.print(temp);<br>
   }<br>

<br> The variable has two different meanings at various stages of the method. Give each variable a descriptive name making it easier to understand the code.<br> <br>

   foo() {<br>
       int perimeter = 2 * (height + width);<br>
       System.out.print(perimeter);<br>
       int area = height * width;<br>
       System.out.print(area);<br>
   }
Personal tools