Question | Value |
1 | 15 |
2 | 15 |
3 | 15 |
4 | 15 |
5 | 20 |
6 | 20 |
Total | 100 |
1. Write a java expression whose value is a random integer in the set [start, start+1, start+2, ..., end], for int variables start and end. Assume that end > start. If this cannot be done, explain why.
2. Write a java statement that assigns 7 to int variable j, if the value of int variable i is evenly divisible by 2 and 3 and is evenly divisible by neither 5 nor 7, and assigns -7 to int variable j otherwise. Do not nest if statements.
3. Convert
the following code fragment to an equivalent one that uses a switch
statement. If this cannot be done, explain why.
5. Write a java method, summer, that takes an argument, data, that is an int array, and an argument top, that is an int, and returns, as a float, the sum of the odd elements of the array, data, (which starts with element 0) whose indices are less than top.
6. Write a java method, maximizer, that takes 2 int arguments: a doubly-subscripted array, table, and an array, max. The method puts the maximum element of row i of table into element i of max.