File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Increment Operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Increment Operator" Watch "Increment Operator" New topic

Increment Operator

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 423

Here increment operators at Line # 9 and 17 aren't working as expected. Please advice if you have any idea

OCPJP 6.0-81% | Preparing for OCWCD | |
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
at these lines the value of 'i' is assigned first to the variable at left hsnd side and then increased by 1. So, when the value is assigned it is '0'.

SCJP 1.6 96%
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

if you replace this


SCJP6.0,My blog Ranchers from Delhi
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Shanky Sohar wrote:if you replace this


Why keep it complicated? Just lose the assignment and use i++;

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Mina Daoud
Ranch Hand

Joined: Sep 24, 2010
Posts: 88
why are you using
using will do the job and keep your code clean and simplified!
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446

Neha has solved the problem
but let me explain a little more

well we will go through some rules
  • increment operator is used AFTER the variables has been used
  • here = operator comes into act before the ++ operator

  • so in this case
    suppose value of i = 0
    at first, i = 0 happens
    and hence when printing value of i we get 0 as output

    hope this helps

    SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
    If you find any post useful, click the "plus one" sign on the right
    I agree. Here's the link:
    subject: Increment Operator
    It's not a secret anymore!