Re: Begginer with Methods
Assign the returned value to a variables. Your method returns whatever the value for number1 is within the method but the main method does not know what to do with it because you are not storing it.
Code:
int answer = lcm(6,8)
Within your main you can now use variable answer and it will be the value returned by the lcm method. By the way you may want to check your LCM method since it will never return the lcm.
Code:
//Loop iteration 1
6 = 6 + 6;
8 = 8 + 8;
//Loop iteration 2
12 = 12 + 6;
16 = 16 + 8;
//Loop iteration 3
18 = 18 + 6;
24 = 24 + 8;
//Loop iteration 4
24 = 24 + 6;
32 = 32 + 8;
As you can see the LCM should be 24 but since they are at 24 at different loop iterations it will never break out of the loop until it reaches 100 iterations.