Programming Fundamentals (Java) With Comments
Programming Fundamentals (Java) With Comments
Instructions:
Read and understand each statement carefully. Avoid unnecessary erasures
Use black or blue ball pen ONLY. Anyone who is caught cheating will be penalized.
I. Multiple Choice: Choose and encircle the best/correct answer. (35 pts)
a. if(saleAmount = 1000)
b. if(saleAmount >= 999)
c. if(saleAmount > 1001)
d. if(saleAmount > 999)
a. loopCount = 5; c. loopCount = 4;
while (loopCount > 3 ); while (loopCount < 3 );
{ {
System.out.println(“Hello”); System.out.println(“Hello”);
loopCount = loopCount – 1; loopCount = loopCount + 1;
} }
b. loopCount = 2; d. loopCount = 1;
while (loopCount < 3 ); while (loopCount < 3 );
{ {
System.out.println(“Hello”); System.out.println(“Hello”);
} loopCount = loopCount +1;
}
3. When a source of random numbers produces each number in its range equally often, the distribution of numbers is said to be:
a. Uniform
b. Uninformed
c. Even
d. Equal
a. rand.nextInt(9) c. rand.nextInt(1,10)
b. rand.nextInt()*10 d. rand.nextInt(10)
7. Assume that a random number generator has been constructed with Random rand = Random(); Which of the following randomly
selects an integer from the range 10, 11, 12, 13, 14, 15?
a. rand.nextInt(5) c. rand.nextInt(10,15)
b. rand.nextInt(6) + 10 d. rand.nextInt(5) + 9
Page 1 of 6
LYCEUM OF THE PHILIPPINES-LAGUNA
Makiling, Calamba City
9. When a new object is constructed using new Random(), what is the seed based on?
12. A teacher wishes wants a random selection A, B, C, D, E for the answers to a multiple-choice test. Which of the following can be
used?
}
Pick a condition for the while statement.
a. redLevel == 0.0 b. redLevel > 0.001
Page 2 of 6
LYCEUM OF THE PHILIPPINES-LAGUNA
Makiling, Calamba City
int j = 1;
while ( j < 10 )
{
System.out.print( j + " " );
j = j + j%3;
}
What is output to the monitor?
a. 1 4 7 c. 1 2 5 8
b. 1 4 7 10 d. 1 2 4 5 7 8
23. What three parts of a counting loop must be coordinated in order for the loop to work properly?
a. initializing the counter, testing the counter, changing the counter
b. initializing the condition, changing the condition, terminating the loop
c. the while, the assignment, and the loop body
d. The while statement, the if statement, and sequential execution.
24. Another word for "looping" is:
a. Recapitulation c. Iteration
b. Tintinnabulation d. Reiteration
25. What makes a loop a counting loop?
a. A loop control variable is tested in the while statement, and is changed each time the loop body executes,
b. A counter is counted upwards by one until it hits a particular limit.
c. A counter is counted downwards by one until it hits zero.
d. No loop control variables are used.
26. Examine the following code:
int count = 0;
while ( count <= 6 )
{
System.out.print( count + " " );
count = count + 2;
}
System.out.println( );
What does this code print on the monitor?
a. 1 2 3 4 5 6 c. 024
b. 0 2 4 6 8 d. 0246
27. Examine the following code:
int count = 7;
while ( count >= 4 )
{
System.out.print( count + " " );
count = count - 1;
}
System.out.println( );
int count = -2 ;
while ( count < 3 )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println( );
int count = 1;
while ( count < 5 )
{
System.out.print( count + " " );
}
System.out.println( );
int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println( );
33. What does the following code fragment write to the monitor?
System.out.println("the prize.");
If (6 > 8)
{
System.out.println(x);
Else
System.out.println(x + 5);
a. 0 c. 10
b. 5 d. None of the choices
int count = 1;
int num = 25;
while (count < 25)
{
num = num -1;
count++;
}
System.out.println(count + “ “ + num);
Page 5 of 6
LYCEUM OF THE PHILIPPINES-LAGUNA
Makiling, Calamba City
Prepared by:
Rolando P. Recto
Instructor
Page 6 of 6