Name:______
Covers Chapters 1 and 2 (50 mins) / CSCI 1301 Introduction to Programming
Armstrong Atlantic State University
Instructor: Y. Daniel Liang

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

5 quizzes for Chapter 1

1 Java ______can run from a Web browser.

A. applications

B. Micro Edition programs

C. servlets

D. applets

2 Which of the following statements is true?

A. A Java applet can be executed from a Web browser.

B. A Java application can be executed from a Web browser.

3 The hex value 7A is ______in binary.

A. 1111110

B. 10111010

C. 1111011

D. 1111010

E. 11110101

4 Java is an object-oriented programming language.

A. true

B. false

5 The binary representation of decimal 49 is ______.

A. 110011

B. 110001

C. 110000

D. 110101

E. 111001


20 quizzes for Chapter 2

6 Math.pow(2, 3) returns ______.

A. 8;

B. 8.0;

C. 9;

D. 9.0;

7 To improve readability and maintainability, you should declare ______instead of using literal values such as 3.14159.

A. constants

B. variables

C. classes

D. methods

8 Which of the following expression results in a value 1?

A. 37 % 6

B. 25 % 5

C. 15 % 4

D. 2 % 1

9 The Unicode of 'a' is 97. What is the Unicode for 'c'?

A. 96

B. 98

C. 97

D. 99

10 A Java character is stored in ______.

A. four bytes

B. two bytes

C. three bytes

D. one byte

11 If you attempt to add an int, a byte, a long, and a double, the result will be a ______value.

A. long

B. byte

C. double

D. int

12 What is y displayed?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x + x++;
System.out.println("y is " + y);
}
}

A. y is 2.

B. y is 1.

C. y is 4.

D. y is 3.

13 The expression (int)(76.0252175 * 100) / 100 evaluates to ______.

A. 76.03

B. 76.0252175

C. 76.02

D. 76

14 According to Java naming convention, which of the following names can be variables?

A. class

B. totalLength

C. TOTAL_LENGTH

D. FindArea

E. findArea

15 Which of the following are correct names for variables according to Java naming conventions?

A. RADIUS

B. findArea

C. radius

D. Radius

E. FindArea

16 To assign a value 1 to variable x, you write

A. x := 1;

B. 1 := x;

C. 1 = x;

D. x == 1;

E. x = 1;

17 The ______method parses a string s to a double value.

A. double.parse(s);

B. Double.parsedouble(s);

C. double.parseDouble(s);

D. Double.parseDouble(s);

18 To add number to sum, you write (Note: Java is case-sensitive)

A. sum = Number + sum;

B. number += sum;

C. number = sum + number;

D. sum += number;

E. sum = sum + number;

19 Suppose a Scanner object is created as follows:
Scanner scanner = new Scanner(System.in);
What method do you use to read an int value?

A. scanner.nextInteger();

B. scanner.integer();

C. scanner.int();

D. scanner.nextInt();

20 An int variable can hold ______.

A. 120.0

B. 'x'

C. "120"

D. 120

E. "x"

21 Which of the following operators has the highest precedence?

A. +

B. casting

C. *

D. /

22 Which of the following is a constant, according to Java naming conventions?

A. ReadInt

B. read

C. MAX_VALUE

D. Test

23 A variable may be assigned a value only once in the program.

A. false

B. true

24 You can define a constant twice in a block.

A. true

B. false

25 A Java statement ends with a ______.

A. period (.)

B. closing brace

C. semicolon (;)

D. comma (,)

Part II: Find and correct errors in the following code:

(5 pts)

public class Test {

public void Main(String[] args) {

int j = i + 1;

int k = 5.5;

System.out.println("j is " + j + "and

k is " + k);

}

}

Part III: Show the output of the following code:

(5 pts)

public class Test {

public static void main(String[] args) {

int x1, x2, i, j, k, y, z;

float f;

x1 = 1;

x2 = 1;

y = 5 + x1--;

z = 5 + ++x2;

i = 6 % 4;

j = 1;

j += j + 3;

k = 25 / 2;

f = (float)((2 / 5) * k);

System.out.println("x1 is " + x1);

System.out.println("x2 is " + x2);

System.out.println("i is " + i);

System.out.println("j is " + j);

System.out.println("k is " + k);

System.out.println("y is " + y);

System.out.println("z is " + z);

System.out.println("f is " + f);

}

}


Key for Exam 1

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

Keys:

1. D
2. A
3. D
4. A
5. B
6. B
7. A
8. A
9. D
10. B
11. C
12. A
13. D
14. BE
15. BC
16. E
17. D
18. DE
19. D
20. BD
21. B
22. C
23. A
24. B
25. C

Part II: Find all syntax errors in the following code: (Please turn Word Reviewing to

(5 pts)

public class Test

{

public void main(String[] args)

{

int i = 0;

int j = i + 1;

int k = (int)5.5;

System.out.println("j is " + j + "and k is " + k);

}

}

Part III: Show the output of the following code:

(5 pts)

public class Test {

public static void main(String[] args) {

int x1, x2, i, j, k, y, z;

float f;

x1 = 1;

x2 = 1;

y = 5 + x1--;

z = 5 + ++x2;

i = 6 % 4;

j = 1;

j += j + 3;

k = 25 / 2;

f = (float)((2 / 5) * k);

System.out.println("x1 is " + x1);

System.out.println("x2 is " + x2);

System.out.println("i is " + i);

System.out.println("j is " + j);

System.out.println("k is " + k);

System.out.println("y is " + y);

System.out.println("z is " + z);

System.out.println("f is " + f);

}

}

x1 is 0
x2 is 2
i is 2
j is 5
k is 12
y is 6
z is 7
f is 0.0

Part IV: Write a complete program named Exam1.java. The program reads three double numbers from the keyboard and displays the average of these three numbers.

(5 pts)

import java.util.Scanner;

public class Test {

/**Main method*/

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// Prompt the user to enter an integer

System.out.print("Enter number1:");

int number1 = input.nextInt();

System.out.print("Enter number2:");

int number2 = input.nextInt();

System.out.print("Enter number3:");

int number3 = input.nextInt();

// Display results

System.out.println("The average is " + (number1 + number2 + number3) / 3);

}

}

1