Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
kindly explain the code.
Joined: Aug 31, 2007
Feb 01, 2008 09:48:00
public static void main(
int x = 11;
x &= 2; //1
System.out.println(x << 2 + x); //2
please explain why this code will print 32 instead of 10(x<<2 will give 8)
Joined: Oct 13, 2005
Feb 01, 2008 10:13:00
Please put all your code in CODE tags; it makes it much easier to read.
It is impossible for anything & 2 to equal 1; in fact 11 & 2 gives 2. The + operator has a higher priority than the bit shift operators, so you are shifting by 4, not by 2.
I agree. Here's the link:
subject: kindly explain the code.
exam watch (page 604) Generics constructor
Expression - How
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013