Quiz
Computer Science Final Exam Practice Combined
This quiz has a time limit, so it opens in the usual player.
Questions in this quiz (44)
1What is the output of this block of code?
place = 10;
if(place == 1) {
System.out.println("Gold Medal!");
} else if (place == 2) {
System.out.println("Silver Medal!");
} else if (place == 3) {
System.out.println("Bronze Medal!");
} else {
System.out.println("No medal.");
}- ASilver Medal!
- BGold Medal!
- CNo medal
- DNothing will print
- EBronze Medal
2What are the values of x and y after this code has executed?
int x = 10;
int y = 5;
if (x >= y) {
x *= y;
} else {
y += x;
}- Ax=50,y=5
- Bx=15,y=5
- Cx=10,y=15
- Dx=10,y=50
3Let's say you are running a program that needs to check if a password is correct. The correct password is "ABCDE" and it needs to match the same capitalization. The user's entry for the password will be stored in a String variable called attempt.
Which expression below will be true if attempt is equal to the correct password?- Aattempt.equals("ABCDE")
- Battempt="ABCDE"
- Cattempt.equalIgnoreCase("ABCDE")
- Dattempt == "ADCDE"
4How many times will this loop run?
public class Main
{
public static void main(String[] args) {
for(int i = 0; i < 10; i++) {
System.out.println("Loop!");
}
}
}- A1 iteration always
- B5 iterations always
- CThis is an infinite loop
- DThis loop will never run
- EDont know- it depends on what the user enters at runtime
- F10 iterations always
5What is a nested loop?
- AThere is no such thing as a nested loop
- BA loop that is placed within another loop
- CA loop that can only run a maximum of 5 times
- DA loop that runs in reverse order
6What will the below block of code print?
boolean x = 4 > 8;
boolean y = 10 > 2;
boolean z = x || y;
System.out.println(z);- A4
- Btrue
- Cfalse
- D8
7What is the difference between the == operator and the = operator?
- A= is the equality operator and == is the assignment operatior
- B== is the equality operator and = is the assignment operator
- Cthe == operator is never correct. = should always be used
- DThe two operators are interchangeable
8What are the two possible values of a while loop condition?
- Ayes and no
- BA and B
- Ctrue and false
- D-1 and 1
9What does the term "iteration" mean?
- AIt refers to a single "run" of a loop
- BIt represents a case statement
- CIt refers to a String variable
- DIt is another term for compilation
10What is the output of this block of code?
int place = 4;
switch (place) {
case 1:
System.out.println("Gold Medal!");
break;
case 2:
System.out.println("Silver Medal!");
break;
case 3:
System.out.println("Bronze Medal!");
break;
}- ABronze Medal!
- BNothing will print
- CGold Medal!
- DSilver Medal!
11Given the following PrintWriter variable, which statement will write the String "Good Morning" to the file Welcome.txt?
PrintWriter output = new PrintWriter("Welcome.txt");- ASystem.out.printIn(output,"Good Morning");
- BWelcome.printIn("Good Morning");
- CPrintWriter.printIn("Good Morning");
- Doutput.printIn("Good Morning");
12What package is imported when we work with Files?
- Ajava.files.*
- Bjava.printer.*
- Cjava.io.*
- Djava.import.*
13Based on the below Scanner object, which of the following statements will read the next value as an int from FileOne.txt?
Scanner reader = new Scanner(new File("FileOne.txt"));- Aint value = reader.nextInt();
- Bint value = reader.readInt();
- Cint value = reader.integer();
- Dint value = reader.next();
14Based on the below Scanner object, which of the following statements will read the next value as a String from GroceryList.txt?
File groceries = new File("GroceryList.txt");
Scanner reader = new Scanner(groceries);- AString value = reader.next();
- BString value = reader.nextInt();
- CString value = reader.readString();
- DString value = reader.string();
15What are possible ways to handle a checked exception? Check all that apply:
- Atry and catch block
- Bimport statement
- CThere is no need to handle them
- Dthrows clause
- Esentinel values
16Take a look at this while-loop header. What do you think this loop is doing?
Scanner input = new Scanner(new File("example.txt"));
while( input.hasNext() ) {- AThis loop allows the program to read to the end of a file
- BThis loop can never run
- CThis loop will run exactly 10 times
- DThis loop header causes a compilation error
17Given a Random object variable named rand, which of the following expressions will generate a random number in the range of 1 through 6?
- Aint randomNumber = rand.nextInt(6);
- Bint randomNumber = rand.nextInt(6+1);
- Cint randomNumber = rand.nextInt(5);
- Dint randomNumber = rand.nextInt(6) +1;
18Which import statement is necessary when using Random?
- Aimport.java.rend.Random;
- Bimport java.util;
- Cimport java.rand;
- Dimport java.utl.Random;
19What is a firewall?
- AA mechanism to monitor and filter network traffic based on a set of rules
- BA password verification tool
- CA data scrambler which encodes secure data
- DA database back up tool
20What is encryption?
- ACopying data and storing in an alternate location
- BScrambling data that can only be retrieved with a unique digital key or algorithm.
- CFiltering network data
21In Java, statements end with a
- A. period
- B; semi-colon
- C# pound sign
- D// two forward slashes
22When is it appropriate to add a comment?
- AAll of these are valid reasons to add a comment
- BTo describe the functionality of a program
- CTo explain the purpose of a variable
- DTo explain what is happening in a single line of code
23What option below is the correct syntax for a single-line comment?
- A// This is a comment
- B... This is a comment
- C! This is a comment
- D# This is a comment
24Which of the below options are Software applications?
- AZoom and Microsoft Word
- BMacOS
- CWindows
25Which statement below successfully stores a value entered by the user? You may assume a Scanner variable called scan has been created.
- Adouble response = scan.getNext();
- BString response = scan.next();
- Cint response = scan.nextDouble();
- DString response = scan.getString();
26Which of the below statements successfully creates an instance of the Scanner tool?
- AScanner scan= Scanner( in );
- BScanner scan = new Scanner(System.in);
- CScanner scan = next Scanner();
- DScanner scan = Scanner(System.in);
27The strict set of rules that must be followed when writing a program, specific to the programming language,is referred to as:
- Alogistics
- Bdesign
- Csyntax
- Dflow
28Which option below is the correct, complete main method signature?
- Apublic static void main(String[] args) {
- Bpublic main(String[] args) {
- Cpublic static main(System.in) {
- DSystem void main(String args) {
29Lets say you have a java source code file called MyProgram,java. What file will be created after MyProgram,java is complied?
- AMyProgram.comp
- BMyProgram.bytecode
- CMyProgram.run
- DMyProgram.class
30Let's say I have an int variable called x, and I would like to double its value. Which statement below will do this?
- Ax *=2;
- Bx += 2;
- Cx = x %2;
- Dx = x / 2;
31Which of the below operators is a Combined Assignment Operator?
- A<=
- B*
- C++
- D/
- E+=
- F!=
32The below block of code will cause a compilation error. Why?
int myValue;
System.out.printIn(myValue);- Aint variables cannot be placed in print statements
- BmyValue is an invalid variable name
- CThere is missing punctuation in this code
- DThe myValue variable has not been initialized
33Which of the below options could be considered an input device?
- ASpeakers
- BComputer Monitor
- CPrinter
- DWeb Camera
34Which of the below options could be considered Hardware? Check all that apply
- ACPU
- BWindows
- CKeyboard
- DMicrosoft Word
- ERAM
- FPhotoshop
35What is cloud storage?
- AFile storage on your physical hard drive
- BFile storage in RAM
- CData clean up and deletion
- DA service provided by a third party company which stores your data on their servers
36Which of the following represents a double literal?
- A1.0
- B1
- C"1"
- D"1.0"
37After this code executes, what is the value of c?
int a = 3;
int b = 2;
int c = a/b;- A0
- B1.5
- C1
- DRuntime Error
38What is the difference between double division and integer division?
- Ainterger division includes a fraction after the decimal point.
double division will drop the remainder, and the result will not include any fraction after the decimal point. - Bdouble division and integer division will always produce the same result
- Cdouble division include a fraction after the decimal point.
integer divison will drop the remainder, and the result will not include any fraction after the decimal point.
- Ainterger division includes a fraction after the decimal point.
39What will the following code print to the output window?
int x =10;
int y = 10;
x=x %4;
y *= 10;
System.out.printIn("x =" + x + '' , y = " + y);- Ax=40, y=100
- Bx=8,y=0
- Cx=2,y=100
- Dx =4,y=10
40Which of the following represents a char literal?
- A'1'
- B1
- C1.0
- D"1.0"
41What will this line of code print to the output window?
System.out.printIn( 3 + 6 + 1 + "abc" );- A3 + 6 + 1 + "abc"
- B361abc
- C10abc
- D91abc
42While will this line of code print to the output window?
System.out.printIn ( "5*5" + "Hello!" );- A10Hello!
- B5*5Hello!
- CHello!Hello!Hello!Hello!Hello!
- D25Hello!
43What are the possible values of boolean variable?
- A-1,0 and 1
- Bon and off
- Ctrue and false
- Dthere is only one possible value for boolean variables:0
44A Java program compiles successfully but throw and exception. What type of error have you encountered?
- Athe Java Virtual Machine
- Bthe JSON virtualization Module
- Cthe Java Visualization Module
- Dthe JSON Visual Machine
- ERuntime Error
Information
- Description
- ACCA Teaching Quiz on Computer Science Final Exam Practice Combined, created by Christopher Castillo on 17/07/2024.
- Author
- Christopher Castillo
- Language
- English
- Views
- 7
- Tags
- Rating
- No ratings yet Rate this quiz