I am learning methods in school and with this program I enter the starting distance type "feet"
it asks me for a double value for it and I entered 12 and I wanted to convert it to yards. It should then let me convert it to imperial or metric units but the out put says 0.0 feet = 0.0 yards.
I debugged the program and my double ft had the value 12 until the method went to its return statement. Does anybody know how to fix this? My code is not that great but it is in the link below. Help is appreciated.
You have encountered the classic "call by reference / call by value" problem. Your code is written with the belief that a variable passed to a function will be altered by the function but in reality it is not. It is best illustrated by a simple code example:
Code:
public class Testing
{
public static void main (String[] args) {
int input = 23;
increment(input, 12);
System.out.println("Main: (1) input now: " + input);
// This time use the return value
input = increment(input, 12);
System.out.println("Main: (2) input now: " + input);
}
public static int increment(int input, int incrementValue) {
System.out.println("Input : " + input);
input += incrementValue;
System.out.println("Input now: " + input);
return input;
}
}
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.