Beruflich Dokumente
Kultur Dokumente
Instructions:
Do not open this exam booklet until you are directed to do so.
Write your full name and Student registration No. clearly on the first page.
When the exam is started, write your complete Student Registration No. clearly on the top of *EVERY* page.
Write your solution in the space provided. If you need more space, write on the back of the sheet containing the problem. If still
you need more space then you can use extra sheets. In the case of extra sheet, clearly mention the question number whose answer
you are giving and you student registration number on the extra sheet.
Plan your time wisely. Do not spend too much time on any one problem. Read through all of them first and attack them in order
that allows you to make the most progress.
Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the
clarity and method correctness with which you express your answer.
Good luck.
1
KINGDOM OF SAUDI ARABIA
Ministry of Higher Education
KING ABDULAZIZ UNIVERSITY
Faculty of Computing and Information Technology كلية الحاسبات وتقنية المعلومات
North Jeddah Branch فرع شمال ﺟﺪة
Student ID: _____________________________
b) Can the following conversions involving type castings are allowed? If yes, find the converted results. (4)
NOTE: ASCII value of ‘A’ is 65, ‘B’ is 66, ‘C’ is 67, ‘D’ is 68 and so on.
ASCII value of ‘a’ is 97, ‘b’ is 98, ‘c’ is 99, ‘d’ is 100 and so on.
char c = 'G';
int i = (int)c;
float f = 945.34f;
int x = (int)f;
double d = 475.34;
int y = (int)d;
int i = 54;
char c = (char)i;
(1) i = 71
(2) x = 945
(3) y = 475
(4) c = ‘6’
c) How would you write the following arithmetic expression in Java? (2)
d) What is the default data type of the literal value 0.46? (1)
double
2
KINGDOM OF SAUDI ARABIA
Ministry of Higher Education
KING ABDULAZIZ UNIVERSITY
Faculty of Computing and Information Technology كلية الحاسبات وتقنية المعلومات
North Jeddah Branch فرع شمال ﺟﺪة
Student ID: _____________________________
e) What is the default data type of the literal value 46? (1)
int
}
Solution:
public class Test{
public static void main (String []args){
int i = 100;
double j;
j = 45.78;
double k = j + i;
System.out.print(“the value of k is ” + k);
}
}
System.out.println("1" + 1);
System.out.println('1' + 1);
System.out.println("1" + 1 + 1);
System.out.println("1" + (1 + 1));
System.out.println('1' + 1 + 1);
11
50
111
12
51
h) Declare a double variable named miles with initial value 100; (1)
3
KINGDOM OF SAUDI ARABIA
Ministry of Higher Education
KING ABDULAZIZ UNIVERSITY
Faculty of Computing and Information Technology كلية الحاسبات وتقنية المعلومات
North Jeddah Branch فرع شمال ﺟﺪة
Student ID: _____________________________
i = 11
m = 120
j = 33
n = 56
k) Syntax errors are those errors that are detected by compiler. (1)
m) Logical errors are done by the programmer and are hard to identify. (1)
4
KINGDOM OF SAUDI ARABIA
Ministry of Higher Education
KING ABDULAZIZ UNIVERSITY
Faculty of Computing and Information Technology كلية الحاسبات وتقنية المعلومات
North Jeddah Branch فرع شمال ﺟﺪة
Student ID: _____________________________
a) Write a Java program TicTacToeBoardPrinter that prints a Tic Tac Toe board like (10)
+––––+––––+––––+
| | | |
+––––+––––+––––+
| | | |
+––––+––––+––––+
| | | |
+––––+––––+––––+
public class TicTacToeBoardPrinter{
public static void main (String []args){
System.out.println(“+ – – – – + – – – – + – – – – +”);
System.out.println(“| | | |”);
System.out.println(“+ – – – – + – – – – + – – – – +”);
System.out.println(“| | | |”);
System.out.println(“+ – – – – + – – – – + – – – – +”);
System.out.println(“| | | |”);
System.out.println(“+ – – – – + – – – – + – – – – +”);
}
}
b) Finding runway length: Given an airplane’s acceleration a and take-off speed v, you can compute the
minimum runway length needed for an airplane to take off using the following formula:
Write a Java program that prompts the user on console to enter v in meters/second (m/s) and the
acceleration a in meters/second squared and displays the minimum runway length. (10)
import java.util.Scanner;
public class RunwayLength{
public static void main (String []args){
double v, a, length;
Scanner input = new Scanner(System.in);
System.out.print (“Enter the value of Speed of Airplane in meter per second : ”);
v = input.nextDouble();
System.out.print (“Enter the value of Acceleration of Airplane in meter per second square : ”);
a = input.nextDouble();
length = (v * v)/(2 * a);
System.out.print(“The minimum length of the runway is ” + length);
}
}