See below for the modified program in Java
The for loop statements in the program are:
To use the enhanced for loop, we make use of the for each statement.
This syntax of the enhanced for loop is:
for(int elem : elems)
Where elem is an integer variable and elems is an array or arrayList
So, we have the following modifications:
Hence, the modified program in Java is:
class Main {
static int[] createRandomArray(int nrElements) {
Random rd = new Random();
int[] arr = new int[nrElements];
int i = 0;
for (int num : arr){
arr[i] = rd.nextInt(1000);
i++;
}
return arr;
}
static void printArray(int[] arr) {
for (int num : arr) {
System.out.println(num);
}
}
}
public static void main(String[] args) {
int[] arr = createRandomArray(5);
printArray(arr);
}
}
Read more about enhanced for loop at:
https://brainly.com/question/14555679
#SPJ1