Alfaisal University - College of Engineering
Software Engineering Department
Subject: SE 100 Programming for Engineers
Major Exam #1 (Fall 2017-2018) – SAMPLE EXAM
Multiple Choice Questions
For each question select the letter of the correct answer. There is only one correct answer for
each question. Write your answers in the scantron answer sheet provided with the exam.
[1 mark for each question]
1) Java is an example of a(n)
a. French language
b. Assembly language
c. High-level language
d. Machine language
2) A Java program is best classified as
a. hardware
b. software
c. storage
d. processor
3) ________________ causes the program to terminate.
a. a logical error
b. a compile-time error
c. a run-time error
d. a bug
4) The Java compiler translates Java source code into _____________.
a. Java bytecode
b. assembly code
c. C++
d. C#
5) Mistyping “println” as “printn” will result in
a. a logical error
b. a syntax error
c. a run-time error
d. no error at all
6) The following code will:
int x = 3/0+2;
a. Work correctly
b. Generate run-time error
c. Generate logic error
d. Generate syntax error
7) Suppose a Scanner object is created as follows:
Scanner input = new Scanner(System.in);
What method do you use to read an integer value?
a. input.nextint();
b. input.nextInt();
c. input.int();
d. input.Int();
8) Which of the following is a valid identifier?
a. $-343
b. Public
c. 2x
d. x@y
9) The following code will print.
public class Test {
public static void main(String[] args) {
String goodbye= "Goodbye";
System.out.println("Goodbye " + goodbye);
}
}
a. goodbye goodbye
b. goodbye Goodbye
c. Goodbye goodbye
d. Goodbye Goodbye
10) What is x after running the following code:
int x = 5;
x *= (int)2.5;
a. x will be 10
b. x will be 12.5
c. x will be 13
d. The code will not compile
11) Note that the ASCII for character A is 65. What is the output of the following code:
char ch = 'A';
System.out.println (++ch);
a. b b. A c. B d. a
12) The expression "Java" + 1 + 2 + 3 evaluates to___________________.
a) Java123
b) Java6
c) Java 123
d) java 123
13) Every statement in Java ends with ______________.
a) a semicolon (;)
b) a comma (,)
c) a period (.)
d) an asterisk (*)
14) Given: int j = 12, k = 12, m = 7; what is the result of evaluating j%m%k*2:
a. 2 b. 5 c. 10 d. 12
15) Suppose
int x = 1;
x /= 2;
What is x?
a. 0 b. 1 c. 2 d. Illegal expression
16) What is the exact output of the following code?
double area = 25.5;
System.out.println(“area”);
System.out.print(“area=”+area);
a. area25.5area=
b. area area= 25.5
c. areaarea=25.5
d. area
area=25.5
17) Given int x = 3 and double y = 3.1; what is the result of x after x += (int)y * x;
a. Syntax error!
b. 12
c. 12.3
d. 9
18) Note that the ASCII code for character A is 65. If char c = (char) 65. Then, System.out.print(c);
will print.
a. B b. A c. 65 d. Illegal expression
19) An int variable can hold __________.
a. ‘9’
b. 99
c. 9.9
d. a and b
20) Which of the following assignment statements is correct to assign character 5 to c?
a. char c = 5;
b. char c = "5";
c. char c = '5';
d. char c = ‘\u0005’;
21) Which of the following lines allows a programmer to use the Scanner class in a Java program?
a. import java.util.Scanner;
b. using Scanner;
c. include java.util.Scanner;
d. All of the above
22) What is output with the statement System.out.println(“Results=” + x+y);
where int x = 10, y = 5; ?
a. Results=15
b. Results=105
c. Results=10 5
d. Results=x+y
23) Which of the following assignment statement is correct to assign Unicode value to ch variable?
a. char ch = ‘a’;
b. char ch = "a";
c. char ch = '\ua';
d. char ch = ‘\u0041’;