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 simple q but just to confirm 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 "simple q but just to confirm" Watch "simple q but just to confirm" New topic
Author

simple q but just to confirm

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204

class test {
public static void main(String args[]) {
int i,j,k,l=0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);//prints 1
S.o.p(j);//prints 1
S.o.p(k);//prints 1(i have doubt on this ans)
Please could anyone tell me whether my ans are right
Regards
Neha
}
}

nss
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610

it should print 1,2,1
and that result is correct
HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Madan, Gopal
Ranch Hand

Joined: Aug 13, 2001
Posts: 86

Output is 1 and 2 and 1
Bob Young
Ranch Hand

Joined: Dec 23, 2000
Posts: 65
Results after each statement:
k = l++; // i/0, j/0, k/0, l/1(post increment operator)
j = ++k; // i/0, j/1, k/1, l/1
i = j++; // i/1, j/2, k/1, l/1
so prints 1 2 1
HTH
Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
Thanx,
i now got it.
I was getting confused in these increments.
thanxs alot once again
Regards
neha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple q but just to confirm
 
Similar Threads
About instance in. and static initializer
please explain
Marcus Exam 3 Qn# 54
Increment Test
help in writing programme