wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array! 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 "array!" Watch "array!" New topic
Author

array!

sc suk
Greenhorn

Joined: May 01, 2001
Posts: 2
public class lost {
public static void main (String [] args){
int [] array = new int[10];
int i=5;
array[i++]=++i+i++;
System.out.println(array[5]+" "+array[6]+" "+i);
}
}
When i tried to execute this code,i got answers to be as 14 0 8.
Could anybody answer how it could be 14 0 8.
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Suk,
Please refer to my code below to understand the mechanism as to what happens during post increment.

Hope this clears your doubt.
Ravindra Mohan..
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by sc suk:
public class lost {
public static void main (String [] args){
int [] array = new int[10];
int i=5;
array[i++]=++i+i++;
System.out.println(array[5]+" "+array[6]+" "+i);
}
}
When i tried to execute this code,i got answers to be as 14 0 8.
Could anybody answer how it could be 14 0 8.


Could anyone explain why anyone not drunk would write code like this?

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Thomas,
Yeah . Just to test how alert can a person be even after
having drinks.

Could anyone explain why anyone not drunk would write code like this?

Ravindra Mohan.
Micah Holroyd
Greenhorn

Joined: Jan 22, 2001
Posts: 20
The only people I could see writing that code would be drunks, sadists, or writers of Java certification tests!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array!