Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array with enhanced for loop for clarification

 
Kota li
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this Topic for a similar question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic