Split Temporary Variable

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: 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.ou...)
 
Line 1: Line 1:
This is when you have create a temporary variable that you use all the way through a method.
+
This is when you have create a temporary variable that you use all the way through a method.<br>
foo()
+
    foo() {<br>
int temp = 2 * (height + width);
+
        int temp = 2 * (height + width);<br>
System.out.print(temp);
+
        System.out.print(temp);<br>
temp = height * width;
+
        temp = height * width;<br>
System.out.print(temp);
+
        System.out.print(temp);<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>
 
+
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()
+
<br>
int perimeter = 2 * (height + width);
+
    foo() {<br>
System.out.print(perimeter );
+
        int perimeter = 2 * (height + width);<br>
area = height * width;
+
        System.out.print(perimeter );<br>
System.out.print(area);
+
        area = height * width;<br>
 +
        System.out.print(area);<br>
 +
    }

Revision as of 20:43, 6 August 2009

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 );
area = height * width;
System.out.print(area);
}
Personal tools