Font size
WorksheetsFirst Quarter Summative Test - September 19, 2024
Total questions: 81
Worksheet time: 1hrs 24mins
Which of the following is a LEGAL identifier?
Num1+Num2
1stQuarterExam
$finalScore
String
Which of the following statement is CORRECT?
System.out.println(“Be Happy);
System.out.println(“Be Happy”)
System.out.println(“Be Happy”);
System.out.println(Be Happy);
Who is the father of Java?
James A. Gosling
Bill Gates
Steve Jobs
Dennis Ritchie
Which of the following statement is NOT true?
Every Java program starts from a main method
In Java, OK and ok are not the same
// indicates a comment line
Char is a reserved word
Which of the following is NOT a Java data type?
String
double
boolean
static
Which of the following is the equivalent compound statement, x = x + 5;?
x=+5;
x++5;
x+=5;
xx=5;
Which of the following is NOT a correct variable declaration?
int x, y = 10;
double p = 10%;
String message;
char choice = ‘Y’;
What is the output of the statement, System.out.print(15 >= 15);
15
true
false
compile error
Which of the following statement is INCORRECT?
Integer.parseInt(input);
Double.parseDouble(input);
Float.parseFloat(input);
String.parseString(input);
Which of the following does NOT belong to the group?
JOptionPane.INFORMATION_MESSAGE;
JOptionPane.ERROR_MESSAGE;
JOptionPane.QUESTION_MESSAGE;
JOptionPane.WARN_MESSAGE;
What is the result of the logical expression,
(true || false) && (false || false) ?
true
false
What is the output of the statement, System.out.print((int)(5.1+5.3*2)) ?
15
20.8
15. 7
20
Which of the following is NOT a relational operator?
<
<>
>=
!=
Identify the output of the following code:
int grade = 80;
if(grade>80)
System.out.print(“great”);
System.out.print(“job”);
great
job
greatjob
jobgreat
Identify the output of the following code:
String section = “Kindness”;
int grade = 11;
System.out.printf(“Grade %d - %s”, grade, section);
11 Kindness
Grade 11 Kindness
Grade 11 - Kindness
Grade Kindness 11
Identify the output of the following code:
int number = 15;
if(number %2 == 0)
System.out.print(“Even”);
else
System.out.print(“Odd”);
Even
Odd
EvenOdd
OddEven
Identify the output of the following code:
double rate = 45.5;
if(rate > 50.0)
System.out.println(rate * 2);
else if(rate >= 40.0)
System.out.println(rate / 2);
else
System.out.println(rate – 2);
22.75
43.5
102.0
45.5
Which of the following statements produces error?
int c = (a > b) ? 10: 15;
int x = (a % 2==0) ? “even” : “odd”;
String y = (a == “Apple”) ? “fruit”, “vegetable”;
char res = (a != b) ? ‘A’ : ‘B’;
Identify the output of the following code:
int score = 55;
char gender = ‘F’;
if(score > 10 || gender == ‘M’)
System.out.print(“Awesome”);
if(score > 10 || gender == ‘F’)
System.out.print(“Still Awesome”);
Awesome
StillAwesome
AwesomeStillAwesome
No output
Identify the output of the following code:
int num1 = 10, num2 = 15;
int min = (num1 < num2) ? 10 : 15;
System.out.println(min);
10
15
1015
No output
Which of the following is NOT a logical operator?
&&
!
||
!=
Which is the alternative to switch in Java language?
break, continue
for,while
if-else
goto, exit
A switch statement accepts ___ type of data as input.
byte
int
short
all of the choices
A switch fall through occurs in Java only in the absence of ___.
case
break
default
none of these
Identify the output of the following code:
int numFruits = 45;
int choice = 45;
switch(choice) {
case numFruits: System.out.print("APPLE ");
default: System.out.println("ORANGE");
}
APPLE
ORANGE
APPLEORANGE
Compile error
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"); break;
case 30: System.out.println("THIRTY");
}
TEN
TWENTY
THIRTY
TENTWENTY
Which of the following is NOT a reserved word or keyword?
main
class
string
void
Which of the following import statement is INCORRECT?
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.awt.*;
import java.sql;
What is the output of the statement, System.out.println(“\\\\wow////”); ?
\\wow////
\\\\wow////
\\wow//
\\\\wow//
Which of the following is NOT true about a 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 < 5; i++)
System.out.print("&");
&
&&&&
&&&&&
&&&&&&
Identify the output of the following code:
int count = 1;
int x = 5;
while (count < 5){
x = x - 1;
count++;
}
System.out.println(x);
5
4
1
0
Identify the output of the following code:
int num = 6;
while(num >= 0){
if(num % 5 == 0){
num++;
continue;
}
System.out.print(num + " ");
num = num - 2;
}
5 3 2 1
6 4 2 1
5 4 3 2
4 3 2 1
Identify the output of the following code:
int x = 2, y = 6;
do {
x = x + 2;
} while (x < y);
System.out.print(x + " " + y);
2 6
2 4
6 6
6 2
Which of the following stament is INCORRECT?
char[] gender = {‘M’, ‘F’};
String[] colors = {“red”, “green”, “blue”};
double[] salary = new salary[0];
int[] omega = new int[50];
Identify the output of the following code:
String[] names = {“Kylie”, “Aljur”, “AJ”, “JM”};
System.out.println(names[3]);
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[1][2]);
E
Y
I
Z
Identify the output of the following code:
int[] nums = {1, 5, 7, 9, 11, 13, 15, 17};
String str = {"Kindness", "Generosity"};
System.out.println(nums.length);
2
0
8
Compile error
What is the array name of the following statement?
double[] scores = new double[40];
double
new
scores
40
What will be the output to the console of the code below?
int my3DArray[][][]= {{{1,2,3,},{4,5,6}},{{7,8,9},{10,11,12}}};
System.out.println(my3DArray.length);
2
1
3
4
What will be the output to the console of the code below?
int my3DArray[][][]= {{{1,2,3,},{4,5,6}},{{7,8,9},{10,11,12}}};
System.out.println(my3DArray[0][1][0]);
4
1
10
2
What will be the output to the console of the code below?
int my2DArray[][]= {{1,2,3,},{4,5,6},{7,8,9}};
System.out.println(my2DArray[2][2]);
9
8
4
3
Which of the following statements correctly declares a two-dimensional integer array?
int Matrix[ ] = new int[5,4];
int Matrix[ ]; Matrix = new int[5,4];
int Matrix[ ][ ] = new int[5][4];
int Matrix[ ][ ] = int[5][4];
What is the following code doing?
int [ ] [ ] arrayname;
instantiating an array
declaring an array
instantiating a 2D array
declaring a 2D array
How many times does the following method print a *?
9
6
7
10
What does the following code segment print?
5 4 3 2 1
-5 -4 -3 -2 -1
-4 -3 -2 -1 0
for (int count = 1; count <= 10; count++) {
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
}
System.out.println("Welcome to Java");
}
System.out.println("Welcome to Java");
}
for(int i = 0; i < 9; i = i + 3)
out. print("foo");
200 66 22 7 2
66 22 7 2
200 66 22 2
200 66 22
7
What is the output of the following Java code?
int num = 5;
while (num > 5) {
num = num + 2;
}
System.out.println(num);
(a)
A while loop has the following format:
while (condition)
{
...
}
while
{
...
}
continue while (condition)
{
...
}
while [condition]
[
...;
]
What is the output of the following code snippet?
int time = 20;
String result = (time < 18) ? "Good day." : "Good evening.";
System.out.println(result);
20
18
Good day
Good evening
What is the output of the following code snippet?
int income = 150000;
boolean condition = (income >= 100000);
String className = condition ? "First" : "Economy";
System.out.println(className);
150000
100000
First
Economy
What is the output of the following code snippet?
int x = 5;
int y = 10;
int max = (x > y) ? x : y;
System.out.println(max);
5
10
x
y
General format of if-else statement is :
if(condition)
Statement1;
if
Statement1;
else
Statement2;
if(condition)
Statement1;
else
Statement2;
General format of "simple if" statement is
if(condition)
Statement1;
else
Statement2;
if(condition)
Statement;
if
Statement1;
What will be the output of the following code:
int x=0;
if (x < 10) System.out.println("Red");
else if (x >= 50)System.out.println("Blue");
else if (x ==71) System.out.println("Purple");
else System.out.println("Gold");
Red
Blue
Purple
Gold
What will be the output of the following code:
int x=71;
if (x < 10) System.out.println("Red");
else if (x >= 50)System.out.println("Blue");
else if (x ==71) System.out.println("Purple");
else System.out.println("Gold");
Red
Blue
Purple
Gold
What will be the output of the following code:
int x=81;
if (x < 10) System.out.println("Red");
else if (x >= 100)System.out.println("Blue");
else if (x ==71) System.out.println("Purple");
else System.out.println("Gold");
Red
Blue
Purple
Gold
Name the data type: "true"
boolean
char
String
double
Name the data type: 1.0
double
int
char
boolean
Name the data type: '3'
int
char
String
None of the above
Name the data type: false
String
boolean
int
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What data type would you use for storing the average test score in a class?
double
String
int
char
How would you declare a variable storing a person's name?
string name = "Jeff";
name String = "Jeff";
String name = Jeff;
String name = "Jeff";
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Which expression evaluates to false?
15 % 3 < 2
3 * 3 % 2 <= 0
false == false
false == false == false == false
What is the exact output of the following Java statement?
System.out.println(15 / 2);
(a)
What is the exact output of the following Java statement?
System.out.println(3 + 5.3);
(a)
What is the exact output of the following Java statement?
System.out.println(22 / 2.0);
(a)
What is the exact output of the following Java statement?
System.out.println(18 % 7);
(a)
What is the exact output of the following Java statement?
System.out.println(4 * 3.0);
(a)
What is the exact output of the following Java statement?
System.out.println(22 / 2.0);
(a)
What is the exact output of the following Java statement?
System.out.println((int) 4.6);
(a)
What is the exact output of the following Java statement?
System.out.println((double) 16);
(a)
What is the exact output of the following Java statement?
System.out.println((int) 43.59);
(a)
This statement y = y * 5 + z is equivalent to __________.
y *= 5 + z
y =* 5 + z
y = 5 + z;
y * 5 + z = y
This statement z = z % 3 is equivalent to __________.
z %= z + 3
z %= 3
z =% 3
z % 3 = z
In a gymnastics or diving competition, each contestant’s score is calculated by dropping the lowest and highest scores and then adding the remaining scores. Write a program that allows the user to enter eight judges’ scores and then outputs the points received by the contestant. Format your output with two decimal places. A judge awards points between 1 and 10, with 1 being the lowest and 10 being the highest. For example, if the scores are 9.2, 9.3, 9.0, 9.9, 9.5, 9.5, 9.6, and 9.8, the contestant receives a total of 56.90 points.
Class name: GymnasticsScoring
Hint: use Arrays.sort() to sort the elements in ascending order
Using of AI tool is NOT allowed
Paste your source in the space provided
