CJCoding With Joseph
15per day
← Back to Question List
Java Code Walkthrough #27

Enhanced For Loop Does Not Modify Array

mediumArrays

📄 Code

Read carefully — what does this print?
1import java.util.Arrays;
2 
3public class Main {
4 public static void main(String[] args) {
5 int[] nums = {1, 2, 3};
6 
7 for (int x : nums) {
8 x = x * 2;
9 }
10 
11 System.out.println(Arrays.toString(nums));
12 }
13}

🎯 Your Answer