Download SampleExam01(Ch1, 2)..

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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.
B.
C.
D.
applications
Micro Edition programs
servlets
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.
B.
C.
D.
E.
1111110
10111010
1111011
1111010
11110101
4
Java is an object-oriented programming language.
A. true
B. false
5
The binary representation of decimal 49 is ______.
A.
B.
C.
D.
E.
110011
110001
110000
110101
111001
20 quizzes for Chapter 2
6 Math.pow(2, 3) returns __________.
A. 8;
B. 8.0;
C. 9;
1
D. 9.0;
7 To improve readability and maintainability, you should declare
_________ instead of using literal values such as 3.14159.
A.
B.
C.
D.
constants
variables
classes
methods
8
Which of the following expression results in a value 1?
A.
B.
C.
D.
37 % 6
25 % 5
15 % 4
2 % 1
9
The Unicode of 'a' is 97. What is the Unicode for 'c'?
A.
B.
C.
D.
96
98
97
99
10
A.
B.
C.
D.
A Java character is stored in __________.
four bytes
two bytes
three bytes
one byte
11 If you attempt to add an int, a byte, a long, and a double, the
result will be a __________ value.
A.
B.
C.
D.
12
long
byte
double
int
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.
2
C. y is 4.
D. y is 3.
13 The expression (int)(76.0252175 * 100) / 100 evaluates to
_________.
A.
B.
C.
D.
76.03
76.0252175
76.02
76
14 According to Java naming convention, which of the following
names can be variables?
A.
B.
C.
D.
E.
class
totalLength
TOTAL_LENGTH
FindArea
findArea
15 Which of the following are correct names for variables
according to Java naming conventions?
A.
B.
C.
D.
E.
16
A.
B.
C.
D.
E.
17
A.
B.
C.
D.
18
A.
B.
C.
D.
RADIUS
findArea
radius
Radius
FindArea
To assign a value 1 to variable x, you write
x
1
1
x
x
:= 1;
:= x;
= x;
== 1;
= 1;
The __________ method parses a string s to a double value.
double.parse(s);
Double.parsedouble(s);
double.parseDouble(s);
Double.parseDouble(s);
To add number to sum, you write (Note: Java is case-sensitive)
sum = Number + sum;
number += sum;
number = sum + number;
sum += number;
3
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.
B.
C.
D.
20
A.
B.
C.
D.
E.
21
A.
B.
C.
D.
scanner.nextInteger();
scanner.integer();
scanner.int();
scanner.nextInt();
An int variable can hold __________.
120.0
'x'
"120"
120
"x"
Which of the following operators has the highest precedence?
+
casting
*
/
22 Which of the following is a constant, according to Java naming
conventions?
A.
B.
C.
D.
23
ReadInt
read
MAX_VALUE
Test
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 (.)
4
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);
}
}
5
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 {
6
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
7
System.out.println("The average is " + (number1 + number2 + number3) / 3);
}
}
8