for (DataType varName : collectionName) - traverses collectionName from first element to last element storing a copy of each element from collectionName in varName for each iteration of the loop.
When calling a method, put variable name that represents the array as an argument in the method call. (Remember that when passing an array as an argument that changes made by the method to the array are persistent.)
Q1: The following method is intended to return a String formed by concatenating elements from the parameter words. The elements to be concatenated start with startIndex and continue through the last element of words and should appear in reverse order in the resulting string.
public void changeIt (int [] list, int num) {
list = new int[5];
num = 0;
for (int x = 0; x < list.length; x++)
list[x] = 0;
}
public void start() {
int [] nums = {1, 2, 3, 4, 5};
int value = 6;
changeIt(nums, value);
for (int k = 0; k < nums.length; k++)
System.out.print(nums[k] + " ");
System.out.print(value);
}
public void changeAgain (int [] arr, int val, String word) {
arr = new int[5];
val = 0;
word = word.substring(0,5);
for (int k = 0; k < arr.length; k++)
arr[k] = 0;
}
public void start() {
int [] nums = {1, 2, 3, 4, 5};
int value = 6;
String name = "blackboard";
changeAgain(nums, value, name);
for (int x = 0; x < nums.length; x++)
System.out.print(nums[x] + " ");
System.out.print(value + " ");
System.out.print(name);
}