File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# Q on complex assignment operators

Ranch Hand

Joined: Oct 29, 2004
Posts: 52
This question is from whizlabs practice exam.

Check this out:
int i=10, j=3, k=7;
int p=30;
p += k -= j <<= i %= 4
What are the values of i,j,k,p?

This is how I interpret it: From right to left
p += (k -= (j <<= (i %= 4)))
Is this right?
1) (i %= 4) evaluates to 2 so i=2
2) (j <<= (i %= 4)) how do u evaluate j?? What does the <<= operator do?
Thanks
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
i %= 4 ==> 2
j<<= 2 ==> 12
k-=j ==> -5
p+=k ==> 25

"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
p += (k -= (j <<= (i %= 4)))
Is this right?

yes
1) (i %= 4) evaluates to 2 so i=2

yes
2) (j <<= (i %= 4)) how do u evaluate j?? What does the <<= operator do?

shift the bits in j to the left i%4 places

Mike Gershman
SCJP 1.4, SCWCD in process

I agree. Here's the link: http://aspose.com/file-tools

subject: Q on complex assignment operators