• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/25

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

25 Cards in this Set

  • Front
  • Back

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

int[] scores = new int[25];

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

char[] streetAddress = new char[80];

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};

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};

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 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"};

Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens?

An exception will be thrown when that statement is executed.

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

999

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

0

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

a[0]

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

a[33]

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];

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.

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

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 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;

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] += 10;




OR




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

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

a[29] = 5;

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 int s 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;

An array of int s 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 int s 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 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;

Assume that an array of int s 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];

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;