Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Comprog (Review)-October 25, 2022 (PM)

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Identify the output of the following code:

              int num=20;

              switch(num){

                case 10: System.out.println("TEN"); break;

                case 20: System.out.println("TWENTY");

                case 30: System.out.println("THIRTY");

a)

TEN

b)

TWENTY

c)

TWENTY

THIRTY

d)

Compile error

2.

Which of the following is NOT a reserved word or keyword?

a)

main

b)

public

c)

static

d)

string

3.

Which of the following import statement is INCORRECT?

a)

import java.io.*;

b)

import javax.swing.JOptionPane;

c)

import javax.util.Scanner;

d)

import java.io.FileReader;

4.

What is the output of the statement,             

System.out.println(“\\wow//”); ?

a)

\\wow//

b)

\wow/

c)

wow

d)

\wow//

5.

Which of the following is NOT true about loop?

a)

In Java, while is a reserved word

b)

The statement is called the body of the loop

c)

Java has three looping structures: while, for, do-while

d)

In an infinite loop, the loop condition is initially false, but after the first iteration, it is always true

6.

Identify the output of the following code:

for(int i = 0; i < 3; i++)

System.out.print("#");

a)

##

b)

###

c)

####

d)

no output

7.

double[][] colors = new double[3][4];

How many elements does the array colors have?

a)

3

b)

4

c)

7

d)

12

8.

double[][] colors = new double[3][4];

What is the number of columns in the array colors?

a)

3

b)

4

c)

7

d)

12

9.

double[][] colors = new double[3][4];

What is the number of rows in the array colors?

a)

3

b)

4

c)

7

d)

12

10.

double[][] colors = new double[3][4];

What is the data type of the array colors?

a)

colors

b)

new

c)

double

d)

final

11.

Identify the output of the following code:

int count = 1;

int x = 3;

while (count < 3){

x = x - 1;

count++;

}

System.out.println(x);

a)

3

b)

0

c)

-1

d)

1

12.

Identify the output of the following code:

int num = 5;

while(num >= 0){

if(num % 5 == 0){

num++;

continue;

}

System.out.print(num + " ");

num = num - 2;

}

a)

7 5 3 1

b)

6 4 2 0

c)

6 4 2 1

d)

5 4 3 2

13.

Identify the output of the following code:

int num = 6;

while(num >= 0){

if(num % 5 == 0){

num++;

break;

}

System.out.print(num + " ");

num = num - 2;

}

a)

7 5 3

b)

6 4 2

c)

6 4

d)

no output

14.

Identify the output of the following code:

int x = 3, y = 6;

do {

x = x + 2;

} while (x < y);

System.out.print(x + " " + y);

a)

7 6

b)

3 6

c)

6 7

d)

7 5

15.

Which of the following statement is INCORRECT?

a)

char[] gender = {‘M’, ‘F’};

b)

String[] colors = {“red”, “green”, “blue”};

c)

double[] salary = new salary[-5];

d)

int[] omega = new int[50];

16.

Identify the output of the following code:

String[] names = {“Kylie”, “Aljur”, “AJ”, “JM”};

System.out.println(names[2]);

a)

Kylie

b)

Aljur

c)

AJ

d)

JM

17.

Identify the output of the following code:

char[][] letters = {{‘A’, ‘E’, ‘I’, ‘O’, ‘U’}, {‘X’, ‘Y’,’Z’}};

System.out.print(letters[0][4]);

a)

O

b)

U

c)

X

d)

Z

18.

Identify the output of the following code:

char[][] letters = {{‘A’, ‘E’, ‘I’, ‘O’, ‘U’}, {‘X’, ‘Y’,’Z’}};

System.out.print(letters[1][0]);

a)

A

b)

E

c)

X

d)

Y

19.

Which of the following statement is INCORRECT?

a)

String[][] names = {{"alice", "ruby", "nana"}};

b)

int[] scores = {{2, 3, 4}, {5, 6, 7}};

c)

double[][] rates = {{1.4, 1.3, 2.3}, {5.5, 6.6, 8.9}};

d)

none of the choices

20.

A SWITCH case statement in Java is a ___ control statement

a)

Looping

b)

Iteration

c)

Selection

d)

Jump

21.

What is the output of the following statement?

for (int i = 7; i >= 5; i--)

System.out.print("*");

a)

**

b)

*

c)

***

d)

no output

22.

What is the output of the following statement?

int[] scores = {1, 2, 3, 4, 5, 7, 8};

for(int i = 0; i < scores.length; i += 2){

System.out.print(scores[i]);

a)

1357

b)

1358

c)

2468

d)

no output

23.

What is the output of the following statement?

for (int i = 5; i >= 1; i++)

System.out.print("*");

a)

*****

b)

****

c)

no output

d)

infinite loop

24.

What is the output of the following statement?

int i = 2;

while (i < 6) {

  System.out.print("Hey");

  i++;

}

a)

HeyHeyHey

b)

HeyHeyHeyHey

c)

HeyHey

d)

infinite loop

25.

What is the output of the following statement?

for (int i = 1; i <= 1; i--)

System.out.print("*");

a)

*

b)

**

c)

infinite loop

d)

no output