This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Operators" Watch "Operators" New topic
Author

Operators

vikas singh
Greenhorn

Joined: Jan 22, 2001
Posts: 23
Please suggest the following if I compile undermentioned 3 sets separetly :
int a=5;
Set1:
// Here at first println statement, the val. of a is 5, agreed�
// And the second println prints 6, agreed �
System.out.println("val of a :"+(a++)); // o/p=5
System.out.println("val of a :"+(a)); // o/p=6
Set2:
// Here val. of a is incremented first and assigned to
// variable a.I agree �
// And the second println prints 6, agreed �
System.out.println("val of a :"+(a=++a)); // o/p=6
System.out.println("val of a :"+(a)); // o/p=6
Set3:
// Here at first println statement, the val. of a is 5
// the same is assigned
// to variable a, but why incrementation doesn't take
// place after that.
// i.e second println should print 6 as a's value but
// o/p is 5 , Pl suggest.
System.out.println("val of a :"+(a=a++)); // o/p=5
System.out.println("val of a :"+(a)); // o/p=5
Thanks,
Vikas s.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I've a detailed explanation and proof code about this kind of stuff here:
Java Left-to-right rule of evaluation
Thanks!
Roseanne
 
GeeCON Prague 2014
 
subject: Operators