• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Operators

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've a detailed explanation and proof code about this kind of stuff here:
Java Left-to-right rule of evaluation
Thanks!
Roseanne
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic