Study Guide - More Advanced Java
Quiz
•
Computers
•
11th - 12th Grade
•
Practice Problem
•
Hard
Joshua Donato
Used 2K+ times
FREE Resource
Enhance your content in a minute
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider two boolean variables a and b. Which of the following best refactors this code?
if(a && b) System.out.println("a");
if(a || b) System.out.println("a");
if(a) System.out.println("a");
if(b) System.out.println("b");
Answer explanation
Because the same code executes whether b is true or false, it can be ignored entirely. Therefore, the code can be simplified to if(a) System.out.println("a");
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider two boolean variables a and b. Which of the following best refactors this code?
if(b) System.out.println(a?"b":"a");
if(b) System.out.println(a?"a":"b");
if(a) System.out.println(b?"b":"a");
if(a) System.out.println(b?"a":"b");
Answer explanation
The value given to System.out.println() depends on if b is true or false. Therefore, this can be simplified to if(a) System.out.println(b?"b":"a");
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider three boolean variables a, b, and c. Which of the following best refactors this code?
if(a?b:c) System.out.println("Hello!");
if((a && b) || (!a && c)) System.out.println("Hello!");
if(b || c) System.out.println("Hello!");
if(b?a:c&&!a) System.out.println("Hello!");
Answer explanation
Many of these will function the same as in the image, but if(a?b:c) System.out.println("Hello!"); is the simplest.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider three boolean variables a, b, and c. Which of the following best refactors this code?
if(a && (b==c)) System.out.print("Hello!");
if(a && ((b&&c) || !b)) System.out.print("Hello!");
if(a && ((b&&c) || (!b&&!c))) System.out.print("Hello!");
if((b&&c) || !b) System.out.print("Hello!");
Answer explanation
In the inner if-statement, the else if block is only triggered if b is false. Therefore, "Hello!" will be printed only if b and c are both true, or if b and c are both false. Therefore, if(a && (b==c)) System.out.print("Hello!"); will refactor this code.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider three boolean variables a, b, and c. Which of the following best refactors this code?
if(a && (b==c)) System.out.println(b?"Hello!":"Goodbye.");
if(a) {
if(b&&c) System.out.println("Hello!");
else if(!b && !c) System.out.println("Goodbye.");
}
if(a && ((b&&c) || !c)) System.out.println(c?"Hellol":"Goodbye.");
if(a) {
if((b&&c) || !c) System.out.println(c?"Hello!":"Goodbye.");
}
Answer explanation
In fact, all of these will function identically. However, if(a && (b==c)) System.out.println(b?"Hello!":"Goodbye."); is the most simplified. Only if b and c are both true or both false will something be printed. What gets printed depends on if b (and therefore c) is true, or if it's false.
6.
MULTIPLE SELECT QUESTION
45 sec • 1 pt
Which of the following methods will get the union u of two ArrayLists a and b? Select all that apply.
Adding everything from a to u, and everything from b to u.
Deleting everything from a that's in b, then adding everything from a and b to u.
Deleting everything from b that's in a, then adding everything from a and b to u.
Adding everything from a to u that's not also in b, then adding everything from b to u that's not also in a.
Answer explanation
Adding everything from a to u, and everything from b to u will doubly count the intersection of a and b. Adding everything from a to u that's not also in b, then adding everything from b to u that's not also in a will not include the intersection of a and b. Of these options, only deleting everything from a that's in b, then adding everything from a and b to u and deleting everything from b that's in a, then adding everything from a and b to u will work as intended.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider two Squares s and t. Which of the following will swap the values of s and t?
Square u = s; s = t; t = u;
Square u = s; t = u; s = t;
Square u = t; s = u; t = s;
Square u = t; t = u; s = t;
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
10 questions
Keyboarding Terms
Quiz
•
9th - 12th Grade
10 questions
8525 AQA GCSE CS 3.7.1 Introduction to Relational Data
Quiz
•
11th Grade
10 questions
Kolaborasi dalam Masyarakat digital
Quiz
•
12th Grade
10 questions
Administrasi Sistem Jaringan
Quiz
•
12th Grade
10 questions
Tarkie Seminar for Disers
Quiz
•
9th - 12th Grade
10 questions
python-BTxâu
Quiz
•
9th - 12th Grade
15 questions
Herramientas de Google
Quiz
•
12th Grade - University
13 questions
Podsumowanie: binarny, komputer, sieć
Quiz
•
7th Grade - University
Popular Resources on Wayground
5 questions
This is not a...winter edition (Drawing game)
Quiz
•
1st - 5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Identify Iconic Christmas Movie Scenes
Interactive video
•
6th - 10th Grade
20 questions
Christmas Trivia
Quiz
•
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
•
KG - 5th Grade
11 questions
How well do you know your Christmas Characters?
Lesson
•
3rd Grade
14 questions
Christmas Trivia
Quiz
•
5th Grade
20 questions
How the Grinch Stole Christmas
Quiz
•
5th Grade
Discover more resources for Computers
26 questions
Christmas Movie Trivia
Lesson
•
8th Grade - Professio...
15 questions
Christmas Song Emoji Pictionary
Quiz
•
7th - 12th Grade
20 questions
Christmas Movies
Quiz
•
1st - 12th Grade
55 questions
CHS Holiday Trivia
Quiz
•
12th Grade
20 questions
Christmas Movie Trivia
Quiz
•
9th - 12th Grade
29 questions
christmas facts
Lesson
•
5th - 12th Grade
20 questions
Christmas Trivia
Quiz
•
5th - 12th Grade
20 questions
Stages of Meiosis
Quiz
•
9th - 12th Grade
