Java Programming 4th Quarter
Java Programming 4th Quarter
Department of Education
Region VII, Central Visayas
DIVISION OF CITY OF BOGO
CITY OF BOGO SCIENCE AND ARTS ACADEMY
St. Joseph Vill., Cogon, Bogo City, Cebu
Help your classmate build a trust on himself/herself. Do not let him/her cheat.
TEST I. MULTIPLE CHOICE. Encircle the letter of the correct answer. Erasure means WRONG.
1. What character is used to terminate a java statement?
a. ; c. \
b. } d. )
4. What type of loop is ideal in situations where the exact number of iteration is known?
a. for loop c. do…while Loop
b. while loop d. none of the above
6. A continue statement causes the execution to skip to _______. * Each pass through a loop is called iteration
a. at the end of the program c. the statement following the continue statement
b. the first statement after the loop d. the next iteration of the loop
7. A for loop inside another for loop is called a/an _____ loop
a. Bracketed c. Inverted
b. Nested d. Negative
8. If there is more than one statement in the block of a for loop, which of the following must be placed at the
beginning and the ending of the loop block?
a. parentheses ( ) c. brackets [ ]
b. French curly braces { } d. arrows < >
16. How many times will the following code print “Welcome to Java”?
int count = 0;
while (count <=10){
System.out.println(“Welcome to Java”);
count++;
}
a. 9 c. 11
b. 10 d. 0
18. In a group of nested loops, which loop is executed the most number of times?
a. the outermost loop
b. the innermost loop
c. all loops are executed the same number of times
d. cannot be determined without knowing the size of the loops
TEST II. TRUE OR FALSE. Write TRUE(uppercase) for True and FALSE(uppercase) for False.
Given the following Java codes are inside the public static void main() function.
while ( i != 1000 ) {
if ( i % 2 == 0 ) {
i = i + 2;
}
else {
i = i - 1;
}
}
------------------------------------
29. The control variable of a for loop must appear in , , and components of the for statement syntax.
30. The loop body of a do-while loop is executed 1 or more times while the loop body of a while loop is executed 0
or more times.
TEST IV. FINDING THE ERROR. The following Java Program is riddled with errors. Encircle all the errors you can find. Be
specific as possible as you can. The highest possible score is 15/10. Right minus Wrong.
/*
The following Java program is supposed to print a Pascal’s Triangle. The number of rows
will depend on the input from the user. The program keeps asking an input from the user
using while loop. If the user inputs 0, the program terminates. A sample output is
provided below.
*/
import java.util.scanner;
While(r !=0 ){
System.out.println("Enter Number of Rows : ");
r = in.nextInt();
If (r == 0);
break;
for(i=0;i<r;i++)
{
for(x=r; k>i; k++)
{
System.out.printf(" ");
}
num = 1;
for(j=0;j<=i;j++)
{
System.out.print(number+ " ");
number = number * (i - j) / (j + 1);
}
System.out.println()
}
}
}
}
TEST V. CODING: Create a complete Java Program for the following problem / situation. Write your answer at
the back. Please make your penmanship as readable as you can.
1. Display “Java is cool.” n times depending on user’s input. If the user inputs 4, display “Java rocks.” 4 times.
(5 points)
2. Display the numbers 0 to n depending on user’s input. If the user inputs 9, display the numbers 1 to 9.
(5 points)