Friday, May 6, 2011

chapter 8

What will be the value of x[1] after the following code is executed?

int[] x = { 22, 33, 44 };
arrayProcess(x);
...
public static void arrayProcess(int[] a)
{
for(int k = 0; k < 3; k++)
{
a[k] = a[k] + 5;
}
}

==38

A ragged array is
==A two-dimensional array when the rows are of different lengths

What will be the value of x[8] after the following code has been executed?

final int SUB = 12;
int[] x = new int[SUB];
int y = 20;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 5;
}
====60

What would be the results of the following code?

int[] array1 = new int[25];
… // Code that will put values in array1
int value = array1[0];
for (int a = 1; a < array1.length; a++)
{
if (array1[a] < value)
value = array1[a];
}
==value contains the lowest value in array1

What would be the results after the following code was executed?

int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
for(int a = 0; a < x.length; a++)
{
x[a] = y[a];
y[a] = x[a];
}
===x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

What will be the value of x[8] after the following code has been executed?

final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}
===180

If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?
==
for (int row = 0; row < numbers.length; row++)
{
for (int col = 0; col < numbers[row].length; col++)
total += numbers[row][col];
}



What would be the results after the following code was executed?

int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
x = y;
y = x;
===x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

What would be the results of the following code?

int[] x = { 55, 33, 88, 22, 99,
11, 44, 66, 77 };
int a = 10;
if(x[2] > x[5])
a = 5;
else
a = 8;
==  a = 5

If a[] and b[] are two integer arrays, the expression a == b compares the array contents.
==false


Given the following two-dimensional array declaration, which statement is true?

int [][] numbers = new int [6] [9];

~~The array numbers has 6 rows and 9 columns

What does the following statement do?

double[] array1 = new double[10];


~~All of the above

The sequential search algorithm
~~Uses a loop to sequentially step through an array, starting with the first element



Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
~true

Java does not limit the number of dimensions that an array may have.
~true

The binary search algorithm
~~Will cut the portion of the array being searched in half each time the loop fails to locate the search value

What will be the value of x[1] after the following code is executed?

int[] x = {22, 33, 44};
arrayProcess(x[1]);
...
public static void arrayProcess(int a)
{
a = a + 5;
}
~~33

An ArrayList object automatically expands in size to accommodate the items stored in it.
~true


The following statement creates an ArrayListobject. What is the purpose of the notation?

ArrayList<String> arr = new ArrayList<String>();
~**It specifies that only String objects may be stored in the ArrayList object.



What would be the results of the following code?

final int SIZE = 25;
int[] array1 = new int[SIZE];

... // Code that will put values in array1

int value = 0;
for (int a = 0; a < array1.length; a++)
{
value += array1[a];
}
~~~***value contains the sum of all the values in array1


Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement
==str[0].toUpperCase();


In memory, an array of String objects
===Consists of an array of references to Stringobjects


For the following code, what would be the value ofstr[2]?

String[] str = {"abc", "def", "ghi", "jkl"};

==A reference to the String "ghi"


What will be the result of executing the following code?

int[] x = {0, 1, 2, 3, 4, 5};
==An array of 6 values ranging from 0-5 and referenced by the variable x will be created


You can use this ArrayList class method to insert an item at a specific location in an ArrayList.
==add


  What will be the value of x[8] after the following code has been executed?

final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}
==180

In order to do a binary search on an array,
===The array must first be sorted in ascending order



You can use this ArrayList class method to replace an item at a specific location in anArrayList.
==set

This ArrayList class method deletes an item from an ArrayList.
===remove

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
==true

No comments:

Post a Comment