We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

but in that case we would get a space after the last element.
but accroding to test case (given) we should not get a space after last element.
so how can you modify without getting a space at end the end in your code

This....this code works and I still struggle to figure out what it does until I had to write it out on paper to compare with the logic of the equation as the equation requires 2^n.

After several tries and a few hours burn away I finally get it.

## Java Loops II

You are viewing a single comment's thread. Return to all comments →

Will you tell me the Code how it solved.

for (int j = 0; j < n; j++) { a += b; System.out.print(a + " "); b *= 2; } System.out.println();

Thanks for sharing, found it very simple to understand.

Not sure why it's been down voted. It's a brilliant solution. Helped me a lot to understand what's going on. Thanks mate

Out of all the complicated solutions, you gave the simplest solution ever. Brilliant thinking! Thanks for sharing.

I am glad my comment helped you ! Keep Coding :D

really you make it very simple...too good

i didnt understand your logic can u explain it please

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

Just brilliant!!!

LOL! I've made a "local" class similar to pow... XD (And completed the test) But... omg your answer were soo simple and efficient...

This is the best. I was using Math.pow unnecessarily.

good logic but it's is not working giving some runtime exception .

i just want to know that how does your power increments for 2 in this code

for(int i=0;i

look at this

but in that case we would get a space after the last element. but accroding to test case (given) we should not get a space after last element. so how can you modify without getting a space at end the end in your code

you can run and check, if in test case space is not allowed after last element you can add space till n-1 length and skip for other.

thanks for helping us.

This....this code works and I still struggle to figure out what it does until I had to write it out on paper to compare with the logic of the equation as the equation requires 2^n.

After several tries and a few hours burn away I finally get it.