Name:_______________________



Name:____Practice Test ______________

Covers chs 1-6 |Sample Exam | |

Part I: Multiple Choice Questions: (1 pts each)

5 quizzes for Chapter 2

1  To assign a double variable d to an int variable x, you write

A. x = d;

B. x = (int)d;

C. x = (long)d

D. x = (float)d;

2  5 % 2 is _____

A. 0

B. 3

C. 4

D. 1

E. 2

3  You can cast a double value to _______.

A. int

B. float

C. byte

D. long

E. short

4  -15 % 4 is _____

A. -3

B. -1

C. 0

D. -2

E. -4

5  You can assign the value in ________ to an int variable.

A. 93

B. 98.3

C. true

D. 'x'

5 quizzes for Chapter 3

6  What is x after evaluating

x = (2 > 3) ? 2 : 3;

A. 2

B. 3

C. 4

D. 5

7  A break statement is required for a switch-case statement in Java.

A. false

B. true

8  Suppose x=0 and y=0 what is x after evaluating the expression (y > 0) && (1 > x++).

A. 0

B. 1

C. -1

9  You can cast a Boolean value to an int, or an int to Boolean.

A. false

B. true

10  Analyze the following code:

     // Enter an integer

     String numString = JOptionPane.showInputDialog(null,

         "Enter a number:",

         "Exam Input", JOptionPane.QUESTION_MESSAGE);

     int number = Integer.parseInt(numString);

     if (number 0; i--) {

       for (int j = 1; j < i; j++)

         System.out.print(j + " ");

       System.out.println();

     }

(II)

     for (int i = 1; i < 5; i++) {

       for (int j = 1; j < i; j++)

         System.out.print(j + " ");

       System.out.println();

     }

(III)

     int i = 0;

     while (i < 5) {

       for (int j = 1; j < i; j++)

         System.out.print(j + " ");

       System.out.println();

       i++;

     }

(IV)

     int i = 5;

     while (i > 0) {

       for (int j = 1; j < i; j++)

         System.out.print(j + " ");

       System.out.println();

       i--;

     }

A. (II)

B. (III)

C. (IV)

D. (I)

13  What the output of the following code:

for ( ; false ; )

   System.out.println("Welcome to Java");

A. prints out Welcome to Java one time.

B. does not print anything.

C. prints out Welcome to Java forever.

D. prints out Welcome to Java two times.

14  You can always write a program without using break or continue in a loop.

A. true

B. false

15  You can always convert a while loop to a for loop.

A. false

B. true

5 quizzes for Chapter 5

16  What is (int)Math.random()?

A. 1.1

B. 1

C. 0

D. 0.5

17  You can define two methods in the same class with the same name and parameter list.

A. true

B. false

18  A call for the method with a void return type is always a statement itself, but a call for the method with a non-void return type can be treated as either a statement or an expression.

A. true

B. false

19  The actual parameters of a method must match the formal parameters in type, order, and number.

A. false

B. true

20  Math.pow(3, 2) returns _______.

A. 8

B. 8.0

C. 9.0

D. 9

5 quizzes for Chapter 6

21. Which of the following are valid array declarations?

a. char[] charArray = new char[26];

b. int[] words = new words[10];

c. char[] charArray = "Computer Science";

d. double[3] nums = {3.5, 35.1, 32.0};

22. Consider the following code fragment:

int[] list = new int[10];

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

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

Google Online Preview   Download