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 test example on  pre increment and post increment operator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "test example on  pre increment and post increment operator" Watch "test example on  pre increment and post increment operator" New topic
Author

test example on pre increment and post increment operator

ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

hi all
I have a question

Q. Find the output :-
class Compound{
public static void main(String args[])
{
int k=12;
k/=--k;
System.out.println(k);
k*=k++; //Line1
System.out.println(k);

k*=++k; //Line2
System.out.println(k);
}
}
Output is :- 1 1 2



acn anyone explain what happens at line 1 and line 2
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
Take a look at this


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Someone expalin this code's output why not the second SOP gives 2 as output???
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241


Hope it helped
ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

Thanks for your post . it helped me especially the article
Post Increment Operator And Assignment
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
But i still have one doubt when the value ++k in k*=++k rewriting it as k=k*(++k); is incremented first then why not the first k on the right hand side of = also gets incremented ???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: test example on pre increment and post increment operator
 
Similar Threads
Increment Test
please explain
Doubt about wrapper Integer Class
Can you explain this ?
Assigning and Post incrementing: