Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array with enhanced for loop for clarification  RSS feed

 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!