CONFLIP Getting WA

Please tell me the error in my code
http://www.codechef.com/viewsolution/3930436

Hey, just change

if(n&1==0)

to

if((n&1)==0)

This is a common mistake. While dealing with binary operators, β€˜==’ takes precedence over ’

 & 

'.

Hence, β€œ1==0” is computed before "n

 & 

1".

Here is the correct solution - www.codechef.com/viewsolution/3930657

1 Like

Hi

Can you please check my code. It throws WA.

https://www.codechef.com/viewsolution/13362508

guys, please upvote me. i am new here. nad not able to ask question

Thank you very much :slight_smile:

@shainsha you cannot use Scanner and BufferedReader simultaneously on System.in. That is because both Scanner and BufferedReader use buffers to read from the input stream. As a result when you use the Scanner first the Scanner's buffer is filled to it’s capacity (1024 chars), and not just what it returns. Hence what is left for the BufferedReader in the input stream is less than what you think.
In summary, use Scanner or BufferedReader, but not both.

1 Like