This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I need help with the following questions in
I felt the answer would be 21,13,13,13 but the answer is 22,13,13,13.How b is coming as 22?
I felt the answer should be 0, 1, 2, 3, 4, but is 0,0,1,2,3,4.How is the extra 0 coming?
4) why does 11 ^ 5 show 14
5)here a should have been 13(5*2+3) but it is coming as 25.How?
6)Why is this creating an infinite loop?
4.) ^ is the binary XOR operator. The calculation goes like this:
00001011 // 11
00000101 // 5
00001110 // 11 xor 5 = 14
5.) Assignment operators (including compound assignment, like *=) have lowest precedence. The calculation goes:
a *= 2+3;
a *= 5;
a = 5*5;
a = 25;
6.) You get an infinite loop because you're never incrementing the loop variable i. You're passing i to the increment function by value. The function increments a copy of i, and leaves the original variable like it was. A working increment function would look like this:You would call it like this:
Joined: Aug 09, 2010
@Stephan van Hulst thanks for the explanations!.
I have got 1 more question.