G12 1st Quarter Exam
G12 1st Quarter Exam
a. 10 b. 11 c. 16 d. none of these
ANS: A
4. What will be the output of the following code?
int num = 10;
if(num < 0)
num = num + 5;
num++;
System.out.print(num);
a. 10 b. 11 c. 16 d. none of these
ANS: B
5. What will be the output of the following code?
int num = - 10;
if(num > 0) {
num = num + 5;
} else {
num = num - 5;
num--; }
System.out.print(num);
a. -10 b. -15 c. -16 d. none of these
ANS: C
6. What will be the output of the following code?
int num = 10;
if(num > 0)
num = num + 5;
else
num = num - 5;
num--;
System.out.print(num);
a. 100 b. 50 c. 25 d. 0
ANS: B
9. What would be the value of bonus after the following statements are executed?
int bonus, sales = 1000;
if (sales > 1000)
{ bonus = 100; }
if (sales > 750)
{ bonus = 50; }
if (sales > 500)
{ bonus = 25; }
else
{ bonus = 0; }
a. 100 b. 500 c. 25 d. 0
ANS: C
10. What is the value of entry after the following statements are executed?
int entry = 9, number = 3;
if ((entry > 9) || (entry/number == 3))
{ entry--; }
else if (entry == 9)
{ entry++; }
else
{ entry = 3; }
a. 3 c. 9
b. 8 d. 10
ANS: B
11. What will be the output of this code?
int grade = 95; String letterGrade = "C";
if (grade < 90)
if (grade >= 80)
letterGrade = "B";
else
letterGrade = "A";
System.out.println(letterGrade);
a. A b. B c. C d. none of these
ANS: C
12. What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000; char dept = 'S';
if (sales > 100000) {
if (dept == 'R')
{
bonus = 2000;
}
else
{
bonus = 1500;
}
} else if (sales > 75000) {
if (dept == 'R')
{
bonus = 1250;
}
else
{
bonus = 1000;
}
} else {
bonus = 0;
}
a. 2 c. 4
b. 3 d. 7
ANS: C
14. What is the output of the following code?
int k = 4, j = 10;
if ((k < 7) && (j < 10)) {
if (k + j < 20) {
System.out.println("A grade");
} else {
System.out.println ("B grade");
}
} else {
if (k + j < 20) {
System.out.println ("C grade");
} else {
System.out.println ("D grade");
}
}
a. A grade c. C grade
b. B grade d. D grade
if(temperature < 0)
System.out.println("Freezing");
else if(temperature < 30)
System.out.println("Pleasant");
else if(temperature < 50)
System.out.println("Hot");
else
System.out.println("Boiling");
}
}
a. Compilation Error
b. Pleasant
c. Hot Boiling
d. Hot
int i = 51;
}
}
a. Greater than 50
b. Less than 50
c. Compilation error
d. Done
}
}
a. True
b. False
c. Compilation error
d. Runtime error
int a = 25;
if(a < 25)
System.out.println("1");
if(a > 10)
System.out.println("2");
else
System.out.println("3");
}
}
a. 1
b. 2
c. 3
d. Compilation error
}
}
a. 1
b. 2
c. 3
d. None of the above
int a = 2 * 22 + 13 - 21;
int b = 15 * 3 + 17 - 12;
22. How many choices are possible when using a single if-else statement?\
a. 1
b. 2
c. 3
d. 4
23. What does the following code fragment write to the monitor?
int sum = 14;
if ( sum < 20 )
System.out.print("Under ");
else
System.out.print("Over ");
System.out.println("the limit.");
a. Over
b. Under
c. Under the limit
d. Over the limit
24. A sequence of statements contained within a pair of braces ("{" and "}") is called
a:
a. block
b. blob
c. branch
d. brick