File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Increment Operator

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi,

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
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
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

PostIncrementOperatorAndAssignment
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

if you replace this

with


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

Joined: Oct 25, 2008
Posts: 2700

Shanky Sohar wrote:if you replace this

with

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: 440


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
    hence
    at first, i = 0 happens
    and hence when printing value of i we get 0 as output

    hope this helps

    SCJP 6 [86%] June 30th, 2010
    OCPWCD [84%] March 26th, 2012
    OCEJPAD [83%] September 6th, 2014
    If you find any post useful, click the "plus one" sign on the right
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Increment Operator