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.

Yes.This is correct.
But I have one question...
In the series we can see evey value is multiply by b.(either first a also).But in your code I can't see that.
But your one gives correct answer.
Can you please explain that for me?

I used this and this gives wrong answerI can't realize why it is wrong???

## Java Loops II

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

Yes.This is correct. But I have one question... In the series we can see evey value is multiply by b.(

either first a also).But in your code I can't see that. But your one gives correct answer. Can you please explain that for me?I used this and this gives wrong answerI can't realize why it is wrong???This line:

Should be:

Since you're loop from 0 you code is calculating a + 2^0*b twice and you will get a wrong result.

And this line:

The '^' it xor (exclusive or) operator not pow operator. You have to use

`Math.pow();`

or a shift operation.Thank You. I have used the shift operation as you said but two test cases failed out of 5. Could you please help me with this code?