You are viewing a single comment's thread. Return to all comments →
This line:
int ans=a+1*b;
Should be:
int ans = a;
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:
int x=2^j*b;
The '^' it xor (exclusive or) operator not pow operator. You have to use Math.pow(); or a shift operation.
Math.pow();
Seems like cookies are disabled on this browser, please enable them to open this website
Java Loops II
You are viewing a single comment's thread. Return to all comments →
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.