'F' → Fullscreen
Arrays.sort. // Figure 1 — Enhanced for loop vs indexed loopint[] nums = {3, 6, 9};
// Indexedfor (int i = 0; i < nums.length; i++){ System.out.println(nums[i]);}
// For-eachfor (int value : nums){ System.out.println(value);}// Figure 2 — Aliasing exampleint[] a = {5, 10, 15};int[] b = a;
b[0] = 99;
System.out.println(a[0]); // prints 99// Figure 3 — Sorting changes the arrayint[] nums = {7, 3, 8, 1};
Arrays.sort(nums);
// nums is now sorted permanentlypublic class Program{ public static void main(String[] args) { // Task 1 — Enhanced For Loop Practice // // 1) Print all values using a for-each loop // 2) Compute the sum using a for-each loop // 3) Try changing a value inside the loop — what happens?
int[] nums = {4, 7, 2, 9, 5};
int sum = 0;
for (int value : nums) { System.out.println(value); sum += value;
// value = 100; // try this and observe }
System.out.println("Sum: " + sum); }}public class Program{ public static void main(String[] args) { // Task 1 omitted
// Task 2 — Aliasing vs Copying // // 1) Create an alias array and modify it // 2) Create a true copy and modify it // 3) Observe which changes affect the original
int[] original = {1, 2, 3};
int[] alias = original; alias[0] = 99;
int[] copy = new int[original.length]; for (int i = 0; i < original.length; i++) { copy[i] = original[i]; }
copy[1] = 42;
System.out.println("Original:"); for (int v : original) { System.out.print(v + " "); }
System.out.println("\nCopy:"); for (int v : copy) { System.out.print(v + " "); } }}import java.util.Arrays;
public class Program{ public static void main(String[] args) { // Tasks 1 and 2 omitted
// Task 3 — Sorting and Reasoning // // 1) Sort the array // 2) Print before and after // 3) Answer the reflection questions
int[] scores = {88, 73, 95, 67, 81};
System.out.println("Before sort:"); printArray(scores);
Arrays.sort(scores);
System.out.println("After sort:"); printArray(scores); }
public static void printArray(int[] arr) { for (int v : arr) { System.out.print(v + " "); } System.out.println(); }}47295Sum: 27
Original:99 2 3Copy:99 42 3
Before sort:88 73 95 67 81After sort:67 73 81 88 95Submit your code and reflections to the appropriate dropbox.