Complete this code segment intended to get temperatures from the user and assign the values to an array using the companion variable currentSize to indicate the number of elements in the array.
double[] temperatures = new double[365];
int currentSize = 0;
Scanner in = new Scanner(System.in);
while (in.hasNextDouble())
{
if (currentSize < temperatures.length)
{
temperatures[currentSize] = in.nextDouble();
_________________
}
}
| currentSize++; |
|
Complete this code to swap the elements at 0 and 1.
int[] scores = {65, 71, 68, 85, 87, 89, 78};
int temp = scores[0];
scores[0] = scores[1];
scores[1] = ________;
|
temp |
|
Given the following array
int[] values = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 9 }; what is the value of sum after the following loop completes?
int sum = 0;
for (int i = 0; i < 9; i++)
{
sum = sum + values[i];
} |
25 |
|
Given the following array
int[] values = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 9 };
what is the value of total after the following loop completes?
int total = 0;
for (int i = 0; i < 9; i++)
{
if (a[i] > total)
total = a[i];
}
|
9 |
|