This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operators