WorksheetsComprog (Review)-October 25, 2022 (PM)
Total questions: 25
Worksheet time: 13mins
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");
TEN
TWENTY
TWENTY
THIRTY
Compile error
Which of the following is NOT a reserved word or keyword?
main
public
static
string
Which of the following import statement is INCORRECT?
import java.io.*;
import javax.swing.JOptionPane;
import javax.util.Scanner;
import java.io.FileReader;
What is the output of the statement,
System.out.println(“\\wow//”); ?
\\wow//
\wow/
wow
\wow//
Which of the following is NOT true about loop?
In Java, while is a reserved word
The statement is called the body of the loop
Java has three looping structures: while, for, do-while
In an infinite loop, the loop condition is initially false, but after the first iteration, it is always true
Identify the output of the following code:
for(int i = 0; i < 3; i++)
System.out.print("#");
##
###
####
no output
double[][] colors = new double[3][4];
How many elements does the array colors have?
3
4
7
12
double[][] colors = new double[3][4];
What is the number of columns in the array colors?
3
4
7
12
double[][] colors = new double[3][4];
What is the number of rows in the array colors?
3
4
7
12
double[][] colors = new double[3][4];
What is the data type of the array colors?
colors
new
double
final
Identify the output of the following code:
int count = 1;
int x = 3;
while (count < 3){
x = x - 1;
count++;
}
System.out.println(x);
3
0
-1
1
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;
}
7 5 3 1
6 4 2 0
6 4 2 1
5 4 3 2
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;
}
7 5 3
6 4 2
6 4
no output
Identify the output of the following code:
int x = 3, y = 6;
do {
x = x + 2;
} while (x < y);
System.out.print(x + " " + y);
7 6
3 6
6 7
7 5
Which of the following statement is INCORRECT?
char[] gender = {‘M’, ‘F’};
String[] colors = {“red”, “green”, “blue”};
double[] salary = new salary[-5];
int[] omega = new int[50];
Identify the output of the following code:
String[] names = {“Kylie”, “Aljur”, “AJ”, “JM”};
System.out.println(names[2]);
Kylie
Aljur
AJ
JM
Identify the output of the following code:
char[][] letters = {{‘A’, ‘E’, ‘I’, ‘O’, ‘U’}, {‘X’, ‘Y’,’Z’}};
System.out.print(letters[0][4]);
O
U
X
Z
Identify the output of the following code:
char[][] letters = {{‘A’, ‘E’, ‘I’, ‘O’, ‘U’}, {‘X’, ‘Y’,’Z’}};
System.out.print(letters[1][0]);
A
E
X
Y
Which of the following statement is INCORRECT?
String[][] names = {{"alice", "ruby", "nana"}};
int[] scores = {{2, 3, 4}, {5, 6, 7}};
double[][] rates = {{1.4, 1.3, 2.3}, {5.5, 6.6, 8.9}};
none of the choices
A SWITCH case statement in Java is a ___ control statement
Looping
Iteration
Selection
Jump
What is the output of the following statement?
for (int i = 7; i >= 5; i--)
System.out.print("*");
**
*
***
no output
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]);
1357
1358
2468
no output
What is the output of the following statement?
for (int i = 5; i >= 1; i++)
System.out.print("*");
*****
****
no output
infinite loop
What is the output of the following statement?
int i = 2;
while (i < 6) {
System.out.print("Hey");
i++;
}
HeyHeyHey
HeyHeyHeyHey
HeyHey
infinite loop
What is the output of the following statement?
for (int i = 1; i <= 1; i--)
System.out.print("*");
*
**
infinite loop
no output
