CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Enhanced For Loop Does Not Modify Array

Java code walkthrough · Question 27
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