Consider the following code, assuming grade is an int:
Which of the following will always produce the same result as the code above, regardless of the value of grade? (multiple correct answers)
AP CS A Unit 3 2020-2021
Quiz
•
Computers
•
9th - 12th Grade
•
Hard
Julian HS]
Used 16+ times
FREE Resource
30 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following code, assuming grade is an int:
Which of the following will always produce the same result as the code above, regardless of the value of grade? (multiple correct answers)
Answer explanation
This code will replace the original and always work the same. If the grade is less
than or equal to 75, Eh is printed. If grade is greater than or equal to 100, Great is
printed and then the rest in between will receive Good.
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is output by the following code?
11
15
31
error
Answer explanation
The x * 3 is equal to 30 so the first if runs and increments x (which is 10) by one. Then
since 11 is smaller than 31, it will not run the second if, thus printing 11
3.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following incomplete code segment.
Consider the following potential replacements for /* missing code */ . Which of these replacements will cause
the code segment to always print false ? Assume that Math is imported correctly into our program.
(int)(Math.random() * 10) + 20
(int)(Math.random() * 10) + 25
(int)(Math.random() * 10) + 30
(int)(Math.random() + 30)
Answer explanation
Math.random() returns a random value between 0 (inclusive)
and 1 (exclusive). So Math.random()*10 + 20 can give values
between 20.0 and 29.9999... By typecasting the value to an int,
the decimal values are truncated, which gives a range from 20 to
29 inclusive, meaning it never returns 30, and false is always
printed as a result
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Given the variables, which boolean condition is true?
a < b && a == b
a > b || a != b
a < b && a != b
b >= a && a >= b
Answer explanation
This is equivalent to a == b, which is true
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
The following if statement tests the snowfall in Alaska during the months of December, January and February.
Assume low represents a threshold determined to be the least amount of snow required to be normal and high
represents a threshold determined to be the most amount of snow required to be normal and snow represents the
amount of snow in inches for that month. All variables are doubles. It could be replaced with:
Answer explanation
This solution properly splits up the compound boolean expression and created two
nested if/else statements
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
The following truth table matches which boolean condition?(1 is true, 0 is false)
A && ( A || B )
A && ( A && B )
!A && ( A || !B )
A || ( A || B )
Answer explanation
This is equivalent to A || B which the truth table reflects
7.
MULTIPLE SELECT QUESTION
2 mins • 1 pt
A weather app records the current temperature to the nearest degree Fahrenheit using an int variable temp.
The app also uses a String variable tempAdj to store an adjective based on the value of temp which will be used
in a short written summary of the current weather. The values of tempAdj are determined as follows:
Which of the following code segments will correctly set the value of tempAdj for any given value of temp? (Multiple correct answers)
Answer explanation
Both code segments will work as they should. Both start with the hottest condition and
then test using an else if statement until the first condition is met and the tempAdj values
is properly assigned
25 questions
Python Basics Quiz 12 by RK
Quiz
•
11th Grade
28 questions
java conditionals, loops, and methods
Quiz
•
10th Grade
28 questions
Python Functions Review Quiz
Quiz
•
9th - 12th Grade
35 questions
[AP CSP] Programming with Conditionals [If, Elif, Else]
Quiz
•
9th Grade - University
25 questions
Code.org: Web Development: Unit 2 Lessons 1 - 9
Quiz
•
6th - 9th Grade
25 questions
HTML and CSS
Quiz
•
9th - 12th Grade
25 questions
Intro to CS Unit 3 Review
Quiz
•
9th - 12th Grade
26 questions
Java - Flow of Control Quiz
Quiz
•
9th - 12th Grade
25 questions
Equations of Circles
Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)
Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System
Quiz
•
10th Grade
10 questions
Writing and Identifying Ratios Practice
Quiz
•
5th - 6th Grade
36 questions
Prime and Composite Numbers
Quiz
•
5th Grade
14 questions
Exterior and Interior angles of Polygons
Quiz
•
8th Grade
37 questions
Camp Re-cap Week 1 (no regression)
Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review
Quiz
•
10th Grade
25 questions
Equations of Circles
Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)
Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System
Quiz
•
10th Grade
37 questions
Camp Re-cap Week 1 (no regression)
Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review
Quiz
•
10th Grade