Split Temporary Variable

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by Matthew Harward)
 
Line 1: Line 1:
----
+
This is when you have create a temporary variable that you use all the way through a method.<br>
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
+
     foo() {<br>
----
+
         int temp = 2 * (height + width);<br>
=[http://ycybesav.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
+
         System.out.print(temp);<br>
----
+
         temp = height * width;<br>
=[http://ycybesav.co.cc CLICK HERE]=
+
         System.out.print(temp);<br>
----
+
     }<br>
</div>
+
<br>
This is when you have create a temporary variable that you use all the way through a method.&lt;br&gt;
+
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>
     foo() {&lt;br&gt;
+
<br>
         int temp = 2 * (height + width);&lt;br&gt;
+
     foo() {<br>
         System.out.print(temp);&lt;br&gt;
+
         int perimeter = 2 * (height + width);<br>
         temp = height * width;&lt;br&gt;
+
         System.out.print(perimeter);<br>
         System.out.print(temp);&lt;br&gt;
+
         int area = height * width;<br>
     }&lt;br&gt;
+
         System.out.print(area);<br>
&lt;br&gt;
+
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.&lt;br&gt;
+
&lt;br&gt;
+
     foo() {&lt;br&gt;
+
         int perimeter = 2 * (height + width);&lt;br&gt;
+
         System.out.print(perimeter);&lt;br&gt;
+
         int area = height * width;&lt;br&gt;
+
         System.out.print(area);&lt;br&gt;
+
 
     }
 
     }

Latest revision as of 03:11, 25 November 2010

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

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


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.

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