Tom Linton,
Fall 2000, Central College
-
Marcia declared an array of 15 ints, named sprockets using the line:
int sprockets[] = new int[15];
She then attempted
to initialize the array as follows:
for (int i = 1 ; i <= 15 ; i++) {
sprockets[i]=23;
}
Why didn't this
work?
-
How would you find out the number of elements of an array named IDNums?
-
Maxwell declared times to be an array of doubles using:
double[] times;
and then followed this immediately with the line:
times[4] = 5;
What did he forget to do?
-
Write a method named indexOfSmallest that takes an array of doubles
as input and returns the index of the smallest value in the array. For
example, if the array contains the numbers 5.2, 0.7, -3.45, 32.9, then
the method should return 2 (the index of -3.45).
-
Write a method named smallest that takes an array of ints as input and
returns the value of the smallest integer in the array. For example, if
the array contains the integers 23, -4, 98, -2, 0, your method should return
-4. You may call the method indexOfSmallest from the last exercise,
if you desire.
-
Write a method named sumOfSquares that takes an array of doubles
as input and returns the sum of each of the entries in the array squared.
For example, if the array contains 2.1, -3.4, 5.0, your method should return
2.1^2 + (-3.4)^2 + 5.6^2 = 47.33.