This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array with enhanced for loop for clarification
 
Similar Threads
Enhanced for-loop problem
Why will I get this output?
for each loop and array
Arrays
enhanced for loop problem -- from a mock