بسم الله الرحمن الرحيم
كلية البيان – قسم نظم المعلومات
structured Programming With Java – sub exam
Question (1): (40 mark- 4 marks for each)
1- the following are java keywords- list other four java keywords?
public – void – main – for
2- list three of white-space characters?
3- what is the output from the following statements ?
[Link]("This is “ );
[Link](“an Easy Test" );
4- what is the value of d: d=(7+3*4 – 2*(3*4)/2))?
5- What we mean by comments in java? What is the benefits from comments? What are types of
Comments?
6- List the components of method header?
7- what is the difference between method’s parameters and method’s arguments?
8- one kind of data types in java is primitive- this one contains many types ex: byte. List four others?
9- given the following statement: for (int n=12; n >=2;n -=2); Answer these questions:
- Name of the control variable is :
- The initial value of the control variable is :
- Loop-continuation condition is:
10- what is the value of these Math methods: ceil(5.3); - floor(3.9) ?
Question (2): (20 mark- 2 marks for each)
1- With x = 0, which of the following are legal lines of Java code for changing the value of x
to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
a) 1, 2 & 3
b) 1 & 4
c) 1, 2, 3 & 4
d) 3 & 2
2. Decrement operator, –, decreases value of variable by what number?
a) 1
b) 2
c) 3
d) 4
3. Which of the following loops will execute the body of loop even when condition
controlling the loop is initially false?
a) do-while
b) while
c) for
d) None of the mentioned
4. . What is the output of this program?
1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. [Link](++g * 8);
6. }
7. }
a) 25
b) 24
c) 32
d) 33
5. Which of these statement is correct?
a) switch statement is more efficient than a set of nested ifs.
b) two case constants in the same switch can have identical values.
c) switch statement can only test for equality, whereas if statement can evaluate any type of
boolean expression.
d) it is possible to create a nested switch statements.
6-. Which of these have lowest precedence?
a) ()
b) ++
c) *
d) +
7. What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ? expression2 : expression3
a) Integer
b) Floating – point numbers
c) Boolean
d) None of the mentioned
8. What is the value stored in x in following lines of code?
int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
a) 0
b) 8
c) 9
d) 1
9- What is the output of this program?
1. class operators {
2. public static void main(String args[])
3. {
4. int var1 = 5;
5. int var2 = 6;
6. int var3;
7. var3 = ++ var2 * var1 / var2 + var2;
8. [Link](var3);
9. }
10. }
a) 10
b) 11
c) 12
d) 56
10- What is the output of this program?
1. class Output {
2. public static void main(String args[])
3. {
4. int a = 1;
5. int b = 2;
6. int c;
7. int d;
8. c = ++b;
9. d = a++;
10. c++;
11. b++;
12. ++a;
13. [Link](a + " " + b + " " + c);
14. }
15. }
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4
Question (3): (20 mark- 2 marks for each)
Choose from B list the most suitable element that match A’s element.
B list : ++ n , Ignored by the compiler , n ++ , Java keyword , parameter , Invalid java
identifier, for , char , arguments, Valid java identifier
A list
1- comments
2- while
3- GradeBook
4- method’s header
5- preincrement
6- primitive data type
7- white space character
8- method call
9- post increment
10- 4_you
Question (4): (20 mark- 5 marks for each)
1- write aprogram in java that display the following message:” Java is an Easy Language”?
2- Given this java code:
public class MyLoop{
public static void main(String args[]){
int total=0;
int counter =4;
while(counter<21){
total = total+counter;
counter= counter+2;
}// while
[Link](the total of even numbers is”,total);
}//main
}//class
This code calculate the total of even numbers between 3&21, rewrite this
code using while loop?
3- write a program using java, the program prompt the user to input three integers, the
result is the maximum number of these three integers: follow these guides:
a) write class MaximumFinder contains method determineMaximum to receipt these
integers.
b) write class MaximumFinderTest to call method determinemaximum method.
4- what is the output of this code:
public class Grade
{
public static void main( String args[ ] )
{
int grade1 = 65;
int grade2 = 50;
[Link]( grade1 >= 60 ? "Passed." : "Failed." );
[Link]( grade2 >= 60 ? "Passed." : "Failed." );
} // end main
} // end class Grade