Quiz 4 will be on Monday, November 7th. It will cover for loops for arrays and strings as well as number representations (binary, hexadecimal, octal) and unit testing. Here are some review questions:
int[] arr = {3, 5, 8, 10, 3, 4, 5, 3};
for(int i = 2; i < arr.length-2; i+=3)
{
arr[i] = arr[i] - i + 1;
}
System.out.println(arr[1] +" "+ arr[2] +" "+ arr[4] +" "+ arr[5]);
twoBOrNotTwoB
method with a for
loop to that will return whether the String has exactly two 'b' characters in it.
public boolean twoBOrNotTwoB(String a) {
}
sumMod4Is3
method (with a for
loop) to find and return the sum of all the values x in the given array where x mod 4 is 3. (i.e. if the remainder is 3 when dividing by 4)
public int sumMod4Is3 (int[] c) {
}
squareMultiplesOf5
method (with a for
loop) to modify all the values in the array that are multiples of 5 by squaring them. The method must modify the given array and return the same array. (e.g. if the array is {1,3,4,5,10}
, the modified array would be {1,3,4,25,100}
)
public int[] squareMultiplesOf5(int[] b) {
}
shortestString
method (with a for
loop) to find and return the length of the shortest string in a given array of Strings. (e.g. if the array is {"Halloween","Java","Testing","Number"}
, the method would return 4)
public int shortestString(String[] d) {
}
Posted in apcsa