Consider the code segment below
What is printed as a result?
int x = 10;
int y = 20;
System.out.print(y + x / y);
APCSA Unit 3 Review
Quiz
•
Computers
•
9th - 12th Grade
•
Hard
Robyn Rose
Used 24+ times
FREE Resource
13 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the code segment below
What is printed as a result?
int x = 10;
int y = 20;
System.out.print(y + x / y);
1
1.5
3
20
20.5
Answer explanation
ORDER OF OPERATIONS!!!
Division (INTEGER DIVISION) happens FIRST!
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following expressions evaluates to 1?
1. 2 / 5 % 3
2. 2 / (5 % 3)
3. 2 / 5 + 1
1 only
2 only
1 and 2 only
2 and 3 only
1, 2, and 3
Answer explanation
Divided by (/) and mod (%) have the same level of importance, so without parentheses we do them from left to right
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following:
int a = 2;
int b = 6;
int c = 3;
Which of the following expressions evaluates to false?
a < b == c < b
a > b == b < c
a < b != c < b
a < b != c < b
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment
boolean a = true;
boolean b = true;
System.out.print((b || (!a || b)) + " ");
System.out.print(((!b || !a) && a) + " ");
System.out.println(!(a && b) && b);
true false false
true true true
true false true
false true false
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
String str1 = new String("Happy");
String str2 = new String("Happy");
System.out.print(str1.equals(str2) + " ");
System.out.print(str2.equals(str1) + " ");
System.out.print(str1 == str2);
What is printed as a result of executing the code segment?
true true true
true true false
false true false
false false true
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment, which is intended to store the sum of all multiples of 10 between 10 and 100, inclusive (10 + 20 + ... + 100), in the variable total.
int x = 100;
int total = 0;
while( /* missing code */ )
{
total = total + x;
x = x - 10;
}
Which of the following can be used as a replacement for /* missing code */ so that the code segment works as intended?
x < 100
x <= 100
x > 10
x >= 10
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int a = 1;
String result = "";
while (a < 20)
{
result += a;
a += 5;
}
System.out.println(result);
What, if anything, is printed as a result of executing the code segment?
21
161116
161161
Nothing is printing because of an infinite loop.
11 questions
Java Boolean Statements
Quiz
•
11th Grade
15 questions
Java Math
Quiz
•
9th - 12th Grade
11 questions
Casting in Java
Quiz
•
9th - 12th Grade
10 questions
Quiz 15 - Array Basics
Quiz
•
11th Grade
13 questions
Unit 4 AP CSA Review
Quiz
•
12th Grade
10 questions
Study Guide - More Advanced Java
Quiz
•
11th - 12th Grade
15 questions
Unit 8 - Searching and Sorting
Quiz
•
9th - 12th Grade
8 questions
CS A U1 Review
Quiz
•
12th Grade
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
17 questions
Parts of Speech
Quiz
•
7th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression
Quiz
•
9th - 12th Grade
20 questions
Inequalities Graphing
Quiz
•
9th - 12th Grade
10 questions
Identifying equations
Quiz
•
KG - University