Exam: Mid-Term Course Code: CS203 Percentage %20
Academic 2nd Academic N. of Exam
Year: Program: All Paper
University of Level: 2 Department: Exam date: 2023/3/22
Faculty of Computers
Sadat City Computer 20 Time allowed: hour 1 and Artificial
Course Name: Programming- Total score: Intelligence
2
Instructions of Exam:
1. Answer the obligatory questions.
2. Use the blue pen and pencil in answer sheet
3. Allow one sheet answer for every student
4. Is not allowed to borrow the tools (pen, pencils, drawing tools, calculator …etc)
5. Is not allowed to use the cell phone or any of its application during the time of exam
---------------------------------------------------------------- -
Question 1: Choose The Correct Answer (10 Marks)
1. The following code has __________.
public class Test {
public static void main(string[] args) {
System.out.println("Welcome to Java!");
} }
A. a compile error B. a runtime error C. a logic error
2. If a program compiles fine, but it produces incorrect result, then the program
suffers __________.
A. a compile error B. a runtime error C. a logic error
3. What is the output of the following code?
System.out.println("1 + 2 + 3");
System.out.println(1 + 2 + 3);
A. 1 + 2 + 3 followed by 6 B. 1 + 2 + 3 followed by 1 + 2 + 3 C. 6 followed by 6
4. What is i printed?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = ++j + j * 5;
System.out.println("What is i? " + i);
}}
A. 0 B. 1 C. 5 D. 6
5. Suppose you define a Java class as follows, the source code should be stored in a file
named _________.
public class Test { }
A. Test.class B. Test.doc C. Test.txt D. Test.java E. Any name with extension
.java
Question 2: Trace the following code and Answer (10 Marks)
1. Show the output of the following code: [5 Marks]
int[][] array = {{1, 2}, {3, 4}, {5, 6}};
int sum = 0;
for (int i = 0; i < array.length; i++)
sum += array[i][0];
System.out.println(sum);
2. What is the output for the third print statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
3. What is the output of the following program?
public class Test {
private static int i = 0;
private static int j = 0;
public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
Dr.Sara Shehab
Professor of Course SaraA.Shehab Course coordinator Sara A.Shehab
Staff Course Department Head
Exam group )Three members accredited by the faculty committee)
1/2
SQ0000000F101002:نموذج رقم
2018/01/14 )0/2( اإلصدار