Download CSC-111 Intro to Java Programming Exam 1 MULTIPLE CHOICE

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
CSC-111 Intro to Java Programming
Exam 1
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
1) The speed of the CPU may be measured in ________.
A) gigabytes
B) megahertz
C) gigahertz
1)
D) megabytes
2) One byte has ________ bits.
A) 4
B) 16
C) 8
D) 12
3) ________ are instructions to the computer.
A) Programs
B) Software
C) Hardware
D) Keyboards
2)
3)
4) ________ translates high-level language program into machine language program.
A) An assembler
B) A compiler
C) The operating system
D) CPU
4)
5) The main method header is written as ________.
A) public static void main(string[] args)
B) public void main(String[] args)
C) public static void main(String[] args)
D) public static main(String[] args)
E) public static void Main(String[] args)
5)
6) Which of the following statements is correct?
A) Every statement in a program must end with a semicolon.
B) Every comment line must end with a semicolon.
C) Every method must end with a semicolon.
D) Every line in a program must end with a semicolon.
E) Every class must end with a semicolon.
6)
7) Which of the following statements is correct to display Welcome to Java on the console?
A) System.out.print(ʺWelcome to Javaʺ);
B) System.println(ʹWelcome to Javaʹ);
C) System.out.println(ʺWelcome to Javaʺ);
D) System.out.print(ʹWelcome to Javaʹ);
E) System.out.println(ʹWelcome to Javaʹ);
7)
8) Java compiler translates Java source code into ________.
A) another high-level language code
B) Java bytecode
C) machine code
D) assembly code
8)
9) ________ is a software that interprets Java bytecode.
A) Java API
C) Java compiler
9)
1
B) Java debugger
D) Java virtual machine
10) Suppose you define a Java class as follows:
10)
public class Test {
}
In order to compile this program, the source code should be stored in a file named ________.
A) Test.class
B) Test.java
C) Test.doc
D) Test.txt
E) Any name with extension .java
11) The extension name of a Java bytecode file is ________.
A) .class
B) .exe
C) .obj
D) .java
11)
12) The extension name of a Java source code file is ________.
A) .obj
B) .class
C) .exe
D) .java
12)
13) Which of the following lines is not a Java comment?
A) /** comments */
B) ** comments **
C) /* comments */
D) // comments
E) -- comments
13)
14) Which of the following are the reserved words?
A) class
B) static
C) void
D) public
14)
15) A block is enclosed inside ________.
A) quotes
B) brackets
C) parentheses
D) braces
15)
16) Analyze the following code.
16)
I:
public class Test {
public static void main(String[] args) {
System.out.println(ʺWelcome to Java!ʺ);
}
}
II: public class Test { public static void main(String[] args) { System.out.println(ʺWelcome to Java!ʺ); } }
A) Only the code in I can compile and run and display Welcome to Java.
B) Only the code in II can compile and run and display Welcome to Java.
C) Both I and II can compile and run and display Welcome to Java, but the code in II has a better
style than I.
D) Both I and II can compile and run and display Welcome to Java, but the code in I has a better
style than II.
2
17) Which of the following code has the best style?
17)
I:
public class Test {
public static void main(String[] args) {
System.out.println(ʺWelcome to Java!ʺ);
}
}
II:
public class Test {
public static void main(String[] args) {
System.out.println(ʺWelcome to Java!ʺ);
}
}
III:
public class Test {
public static void main(String[] args) {
System.out.println(ʺWelcome to Java!ʺ);
}
}
IV:
public class Test {
public static void main(String[] args) {
System.out.println(ʺWelcome to Java!ʺ);
}
}
A) I
B) II
C) III
D) IV
18) If a program compiles fine, but it produces incorrect result, then the program suffers ________.
A) a compilation error
B) a logic error
C) a runtime error
18)
19) If you forget to put a closing quotation mark on a string, what kind error will be raised?
A) a logic error
B) a runtime error
C) a compilation error
19)
20) Java source code can be executed on a Java Virtual Machine.
A) true
B) false
20)
21) A Java interpreter is a program that translates Java source code into Java bytecode.
A) true
B) false
21)
22) A Java application must have a main method.
A) true
22)
B) false
23) Four bytes have ________ bits.
A) 32
B) 16
C) 64
23)
3
D) 8
24) The compiler generates bytecode even if the program has syntax errors.
A) true
B) false
24)
25) You use ________ to run a Java program.
A) javac
25)
B) java
26) Suppose a Scanner object is created as follows:
26)
Scanner input = new Scanner(System.in);
What method do you use to read an int value?
A) input.nextInteger();
C) input.int();
B) input.nextInt();
D) input.integer();
27) If you enter 1 2 3, when you run this program, what will be the output?
27)
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print(ʺEnter three numbers: ʺ);
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);
}
}
A) 1.0
B) 2.0
C) 3.0
D) 4.0
28) What is the exact output of the following code?
28)
double area = 3.5;
System.out.print(ʺareaʺ);
System.out.print(area);
A) 3.5 3.5
B) area 3.5
C) 3.53.5
D) area3.5
29) Which of the following are correct names for variables according to Java naming conventions?
A) RADIUS
B) findArea
C) FindArea
D) radius
E) Radius
29)
30) Which of the following are correct ways to declare variables?
A) int length, int width;
B) int length; int width;
C) int length; width;
D) int length, width;
30)
4
31) ________ is the Java assignment operator.
A) =:
B) ==
31)
D) =
C) :=
32) To assign a value 1 to variable x, you write ________.
A) 1 = x;
B) x == 1;
C) x = 1;
32)
D) x := 1;
E) 1 := x;
33) Which of the following assignment statements is incorrect?
A) i == j == k == 1;
B) i = 1; j = 1; k = 1;
C) i = j = k = 1;
D) i = 1 = j = 1 = k = 1;
33)
34) To declare a constant MAX_LENGTH inside a method with value 99.98, you write ________.
A) double MAX_LENGTH = 99.98;
B) final float MAX_LENGTH = 99.98;
C) final MAX_LENGTH = 99.98;
D) final double MAX_LENGTH = 99.98;
34)
35) Which of the following is a constant, according to Java naming conventions?
A) Test
B) COUNT
C) read
D) MAX_VALUE
E) ReadInt
35)
36) To improve readability and maintainability, you should declare ________ instead of using literal
values such as 3.14159.
A) classes
B) constants
C) variables
D) methods
36)
37) According to Java naming convention, which of the following names can be variables?
A) findArea
B) FindArea
C) TOTAL_LENGTH
D) totalLength
E) class
37)
38) If a number is too large to be stored in a variable of the float type, it ________.
A) causes overflow
B) causes no error
C) causes underflow
D) cannot happen in Java
38)
39) What is the result of 45 / 4?
A) 12
B) 10
39)
C) 11.25
D) 11
40) Which of the following expression results in a value 1?
A) 37 % 6
B) 15 % 4
C) 2 % 1
41) 25 % 1 is ________.
A) 1
42) -25 % 5 is ________.
A) 1
40)
D) 25 % 5
41)
B) 2
C) 3
D) 4
E) 0
42)
B) 2
C) 3
D) 4
5
E) 0
43) 24 % 5 is ________.
A) 1
43)
B) 2
C) 3
D) 4
44) Math.pow(2, 3) returns ________.
A) 9
B) 9.0
E) 0
44)
C) 8
D) 8.0
45) Math.pow(4, 1 / 2) returns ________.
A) 1
B) 2.0
45)
C) 2
D) 1.0
E) 0
46) Math.pow(4, 1.0 / 2) returns ________.
A) 2.0
B) 1
C) 0
D) 1.0
E) 2
D) 25
E) 20
46)
47) The expression 4 + 20 / (3 - 1) * 2 is evaluated to ________.
A) 4
B) 24
C) 9
47)
48) The System.currentTimeMillis() returns ________.
A) the current time in milliseconds since midnight
B) the current time in milliseconds
C) the current time in milliseconds since midnight, January 1, 1970
D) the current time
E) the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
48)
49) To obtain the current second, use ________.
A) System.currentTimeMillis() % 3600
B) System.currentTimeMillis() % 60
C) System.currentTimeMillis() / 1000 % 60
D) System.currentTimeMillis() / 1000 / 60 % 60
E) System.currentTimeMillis() / 1000 / 60 / 60 % 24
49)
50) To obtain the current minute, use ________.
A) System.currentTimeMillis() % 3600
B) System.currentTimeMillis() % 60
C) System.currentTimeMillis() / 1000 % 60
D) System.currentTimeMillis() / 1000 / 60 % 60
E) System.currentTimeMillis() / 1000 / 60 / 60 % 24
50)
51) To add a value 1 to variable x, you write ________.
A) x = x + 1;
B) x += 1;
C) x = 1 + x;
51)
D) x := 1;
E) 1 + x = x;
52) To add number to sum, you write ________. (Note: Java is case -sensitive.)
A) number += sum;
B) sum = Number + sum;
C) number = sum + number;
D) sum = sum + number;
E) sum += number;
53) Suppose x is 1. What is x after x += 2?
A) 0
B) 1
52)
53)
C) 2
D) 3
6
E) 4
54) Suppose x is 1. What is x after x -= 1?
A) 2
B) 1
54)
C) -2
D) -1
E) 0
55) What is x after the following statements?
55)
int x = 2;
int y = 1;
x *= y + 1;
A) x is 1.
B) x is 2.
C) x is 3.
D) x is 4.
56) Are the following four statements equivalent?
56)
number += 1;
number = number + 1;
number++;
++number;
A) Yes
B) No
57) What is y displayed?
57)
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 1.
B) y is 2.
C) y is 3.
D) y is 4.
58) Which of the following expressions will yield 0.5?
A) 1 / 2.0
B) 1.0 / 2
C) (double) 1 / 2
D) 1 / 2
E) (double) (1 / 2)
58)
59) What is the printout of the following code?
59)
double x = 5.5;
int y = (int)x;
System.out.println(ʺx is ʺ + x + ʺ and y is ʺ + y);
A) x is 5.5 and y is 5.0
B) x is 5 and y is 6
C) x is 6.0 and y is 6.0
D) x is 5.5 and y is 5
E) x is 6 and y is 6
7
60) Which of the following expression results in 45.37?
A) (int)(45.378 * 100) / 100.0
C) (int)(45.378 * 100) / 100
60)
B) (int)(45.378 * 100 / 100)
D) (int)(45.378) * 100 / 100.0
61) The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
A) 76
B) 76.03
C) 76.0252175
62) To declare a constant PI, you write ________.
A) final float PI = 3.14159;
C) final double PI = 3.14159;
61)
D) 76.02
62)
B) final static PI = 3.14159;
D) static double PI = 3.14159;
63) To assign a double variable d to an int variable x, you write ________.
A) x = d;
B) x = (float)d;
C) x = (int)d;
64) What is the printout of the following code:
63)
D) x = (long)d
64)
double x = 10.1;
int y = (int)x;
System.out.println(ʺx is ʺ + x + ʺ and y is ʺ + y);
A) x is 10.1 and y is 10.0
B) x is 10 and y is 10
C) x is 10.0 and y is 10.0
D) x is 11 and y is 11
E) x is 10.1 and y is 10
65) A variable must be declared before it can be used.
A) true
65)
B) false
8
Answer Key
Testname: CSC111EXAM1
1) B, C
2) C
3) A, B
4) B
5) C
6) A
7) A, C
8) B
9) D
10) B
11) A
12) D
13) B, E
14) A, B, C, D
15) D
16) D
17) D
18) B
19) C
20) B
21) B
22) A
23) A
24) B
25) B
26) B
27) B
28) D
29) B, D
30) B, D
31) D
32) C
33) A, D
34) D
35) B, D
36) B
37) A, D
38) A
39) D
40) A
41) E
42) E
43) D
44) D
45) D
46) A
47) B
48) E
49) C
50) D
9
Answer Key
Testname: CSC111EXAM1
51) A, B, C
52) D, E
53) D
54) E
55) D
56) A
57) B
58) A, B, C
59) D
60) A
61) A
62) C
63) C
64) E
65) A
10