my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Array with enhanced for loop for clarification 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 with enhanced for loop for clarification" Watch "Array with enhanced for loop for clarification" New topic
Author

Array with enhanced for loop for clarification

Kota li
Greenhorn

Joined: Sep 05, 2007
Posts: 20
What is the output of this code :

1: int []arr = {1,2,3,4};
2: for ( int i : arr )
3: {
4: arr[i] = 0;
5: }
6: for ( int i : arr )
7: {
8: System.out.println(i);
9: }

This is the output . Why is 0 0 3 0 changed like that pls any a clear that one .

Prints 0 0 3 0

ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
See this Topic for a similar question.
 
GeeCON Prague 2014
 
subject: Array with enhanced for loop for clarification