Florida International University



Florida International University

Review

1. Which of the following statements concerning arrays are true? Select all valid answers.

a) An array is an object.

b) The elements of an array can either be objects or primitive data values

c) All of the elements in an array have the same type.

d) The array size is fixed after it is created.

2. Which of the following statements are true about the class ArrayList? Select all valid answers.

a) The size of the list must be specified at the time of creating the list object.

b) Array list objects can grow dynamically.

c) The elements of an array list must all be objects.

d) The elements of an array list can be any data type.

3. Given the following code:

class Question

{public static void main(String []arg)

{

for (String i = “a”; i < “d”; i++)

switch(i)

{

default:

System.out.println("default");

break;

case “b”:

case “a”:

System.out.print(i + “ “);

break;

}

}

}

What will happen if you attempt to compile and execute the code? Select all valid answers.

a) The code will not compile because the default statement should come last.

b) The code will not compile because String type cannot be used for a loop variable.

c) The code will compile and print the following on one line: a b default

d) The code will not compile because the case value must be integer type.

4. Which of the following statements is true about the for loop and the while loop construct. Select all valid answers.

a) Wherever a while statement is used it can be replaced with a for statement.

b) Wherever a for statement is used, a while statement can replace it.

c) The while statement and the for statement produce the same result when the while statement replaces the for statement.

d) The while statement cannot replace the for statement at any time.

5. Write what will be printed when the following program is executed.

1. class Question

2. {

3. public static void main(String []arg)

4. {

5. int i = 1, m = 3;

6. while(m < 20)

7. {

8. System.out.println(m);

9. i++;

10. m = m * i;

11. }

12. }

13. }

8. What will be displayed on the screen when the following program is executed.

1. class Question

2. {

3. public static void main(String[] arg)

4. {

5. int y = 12, x = 10;

6. while( y != 0)

7. {

8. int r = x % y;

9. x = y;

10. y = r;

11. }

12. System.out.println(x + " " + y );

13. }

14. }

9. Consider the following program segment. How many times does the body of the while statement below get executed?

int x = 3;

while (x < 9)

x = x + 2;

x++;

(a) 3 (b) 4 (c) 6 (d) 8 (e) 9

10. Show the screen outputs of the following program.

public class MyArray

{

public static void main( String [] arg)

{

int count=10;

double [] list = new double[count];

System.out.println(list.length);

for(int i=0; i ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download