0% found this document useful (0 votes)
5 views5 pages

Java Structured Programming Exam Questions

programming exam and solution

Uploaded by

elhaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Java Structured Programming Exam Questions

programming exam and solution

Uploaded by

elhaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

‫بسم الله الرحمن الرحيم‬

‫كلية البيان – قسم نظم المعلومات‬


structured Programming With Java – basic exam
Question (1): (40 mark- 4 marks for each)
1- The following are java keywords- list other two java keywords?
Private – void – main – for
2- List two of white-space characters?
3- What is the output from the following statements?
[Link]("This is easy exam“ );
4- What is the value of d: d = (7+2*(3*4)/2))?
5- What are types of Comments in java?
6- List the components of method header?
7- What is the difference between method’s parameters and method’s arguments?
8- List two of data types in java?
9- Given the following statement: for (int i=12; i >=2;i -=2); Answer these
questions:
- Name of the control variable is :
- The initial value of the control variable is :
10- give two characteristics for pseudo code?
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. Increment operator, ++, increase value of a 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 i = 3;
5. [Link](++i * 8);
6. }
7. }

a) 25
b) 24
c) 32
d) 33

5. Which of these statements 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 : ++i , Ignored by the compiler , i++ , Java keyword , parameter , Invalid java
identifier, for , char , arguments, Valid java identifier
A list
1- comments Ignored by the compiler
2- while Java keyword
3- GradeBook Valid java identifier
4- method’s header parameter
5- preincrement ++i
6- primitive data type char
7- white space character
8- method call arguments
9- post increment i++
10- 4you Invalid java identifier

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 for 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

You might also like