SJSU/Udacity CS046

Problem Set 7

  1. Arrays 1
  2. Arrays 2
  3. Arrays 3
  4. Array Algorithms
  5. Reverse Array
  6. Count Matches
  7. Fill Array
  8. Array Methods
  9. Temperature 1
  10. Temperature 2

Array Algorithms

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

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =