File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes working of increment operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "working of increment operator" Watch "working of increment operator" New topic

working of increment operator

D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Hi All,

I just saw 2 questions on the working of increment operator and, couldn't understand the output for them. Can someone please explain?

Ques 1.

output: 13:0

Ques 2:

output: 14:0

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
Java arithmetic works from left to right. The [] has a high precedence, rather like (), so the i++ in the [] is evaluated first, then the i++ after the = then the 3ed i++.

Remember that i++ increments the value of i, but the whole expression returns the old value of i.

Now you should be able to work it out for yourself.
I agree. Here's the link:
subject: working of increment operator
It's not a secret anymore!