Math with Loops Comments
Comments
-
I can't solve this problem. The cheat button isn't visible too. Help Me.
-
It can be solved with either kind of loop. This question may be too hard, so I will add some more explanation (and a cheat option).
-
Update: I created a new easier challenge for the While and For Loops Node. I changed this node to Loopy Thinking, and added some more help.
-
This is what I did, I don't understand the setting of variable to 1, I set mine to 2 and it worked.
public static int doStuff(int a, int b){
int product=a;
for(int i=2;i<=b;i=i+1){product=product*a;}
return product;
} -
I changed it, and it still works, but i think this is more correct and will have less errors with certain numbers. public static int doStuff(int a, int b){
int product=1;
for(int i=1;i<=b;i=i+1){product=product*a;}
return product; -
James, I changed the explanation to just show the code. My mention of setting the variable to 1 would have been relevant if I had cases where the exponent was 0, but I decided to leave them out. This means your first solution would also work.
-
(complete noob running through ) I cant figure this out :(. Can someone please explain what is happening with the Zonko problem...
-
@moses, there are now 3 challenges which all follow the same idea...
-
Anyone having problems, try thinking about it as that a needs to be multiplied by a, b amount of times.
-
This was a tough one. I originally put the following code, which was incorrect:
int solution = 0;
for (int i=0; i<=b; i++)
{
solution += (a * a);
}
return solution; -
The best thing to do is to take physical notes of the previous lesson and come back to here. My notes really helped.
-
Thanks much from learneroo for helping noobs like myself to learn a bit more. My 25 cents for this exercise even though i may be going to ahead of time is that it would have been useful to know
that the return must go out of the for loop and the reason.. Or was this explanation on an old lesson o_O? Anyway cheers yall!
-
This is the easiest way
<<int Solution = (int) Math.pow(a, b);
return Solution; -
int solution = 1; for(int i=1; i <= b; i =i+1){ solution = a * solution; } return solution;
-
I'm stuck on the first one. The loop stops when the condition is no longer true. If I do a+b>i; . Sum=sum+1 aka a=a+1; will run until the condition is no longer true. However I keep getting incorrect. Appreciate the advice thanks.
-
@learneroo can I get some help in reference to my comment. Thank you.
-
a+b>i
does not work as the condition since it doesn't look ati
. Try it out with an example, e.g. where a is 3 and b is 5. Also, the goal is to not add numbers greater than 1 together. How many times should you add 1 toa
to reach a+b?
Jay Learn
Jul 23, 10:28 AMIt would have been easy if you would have mentioned whether the given problem is to be solved using 'for' or 'while' loop!