MyProgrammingLab 7.2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Assume that the array arr has been declared. Write a statement that assigns the next to last element of the array to the variable x, which has already been declared.

x = arr[arr.length - 2];

An array of 1000 integers has been created. What is the largest integer that can be used as an index to the array? 1001 1000 999

999

Declare an array reference variable, week, and initialize it to an array containing the strings "mon", "tue", "wed", "thu", "fri", "sat", "sun" (in that order).

String[] week = {"mon", "tue", "wed", "thu", "fri", "sat", "sun"};

Given that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 months of the year in order (i.e., January, February, etc.), write a statement that writes to standard output the element corresponding to October. Do not write anything else out to standard output.

System.out.print(monthSales[9]);

Consider the declaration: int v[] = new int[1]; What is the index of the last element of this array? 0 1 2

0

Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? The compiler issues an error message. The compiler issues a warning message. An exception will be thrown when that statement is executed. Another variable or array will be unexpectedly modified.

An exception will be thrown when that statement is executed.

Given an array a, write an expression that refers to the first element of the array.

a[0]

Given that an array named a with elements of type int has been declared, assign 3 to its first element.

a[0] = 3;

Assume that an array named a containing exactly 5 integers has been declared and initialized. Write a single statement that adds 10 to the value stored in the first element of the array.

a[0] = a[0] + 10;

Assume that an array of integers named a has been declared and initialized. Write a single statement that assigns a new value to the first element of the array. The new value should be equal to twice the value stored in the last element of the array.

a[0] = a[a.length-1] * 2;

Given that an array of ints named a with 30 elements has been declared, assign 5 to its last element.

a[29] = 5;

Given an array a, declared to contain 34 elements, write an expression that refers to the last element of the array.

a[33]

Given that an array named a whose elements are of type int has been declared, assign the value -1 to the last element in a.

a[a.length-1] = -1;

Assume that an array of ints named a that contains exactly five elements has been declared and initialized. In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3. Write a single statement that assigns a new value to element of the array indexed by j. This new value should be equal to twice the value stored in the next element of the array (i.e. the element after the element indexed by j.

a[j] = 2 * a[j + 1];

An array of ints named a has been declared with 12 elements. The integer variable k holds a value between 0 and 6. Assign 9 to the element just after a[k].

a[k + 1] = 9;

An array of ints named a has been declared with 12 elements. The integer variable k holds a value between 2 and 8. Assign 22 to the element just before a[k].

a[k-1] = 22;

Assume that an array of ints named a has been declared with 12 elements. The integer variable k holds a value between 0 and 6. Assign 15 to the array element whose index is k.

a[k] = 15;

Write a statement that declares an array named streetAddress that contains exactly eighty elements of type char .

char[] streetAddress = new char[80];

Declare an array named taxRates of five elements of type double and initialize the elements (starting with the first) to the values 0.10, 0.15, 0.21, 0.28, 0.31, respectively.

double[] taxRates = {0.10, 0.15, 0.21, 0.28, 0.31};

Given an array arr, of type int, along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.

int temp; temp = arr[i]; arr[i] = arr[j]; arr[j] = temp;

In a single statement: declare, create and initialize an array named a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20, ..., 100 respectively.

int[] a = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};

Write a statement to declare and initialize an array named denominations that contains exactly six elements of type of int. Your declaration statement should initialize the elements of the array to the following values: 1, 5, 10, 25, 50, 100. (The value 1 goes into the first element, the value 100 to the last.)

int[] denominations = {1, 5, 10, 25, 50, 100};

Declare and instantiate an array named scores of twenty-five elements of type int.

int[] scores = new int[25];

Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declared. Write a single statement to assign the value 30000 to the first element of this array.

salarySteps[0] = 30000;

Assume that an array of integers named salarySteps that contains exactly five elements has been declared. Write a statement that assigns the value 160000 to the last element of the array salarySteps.

salarySteps[4] = 160000;


Conjuntos de estudio relacionados

Chapter 9: Families and Children

View Set

State Law , Rules, and Regulations

View Set

C722 Project Management - Unit 5 & 6 Questions

View Set

Chapter 3: Image Formation and Radiographic Quality

View Set

Chapter 15 Anxiety and Obsessive-compulsive disorders

View Set

CH 5 Infertility, Contraception, and Abortion

View Set

chapter 17 - sports psychology - test 4

View Set