Consider the following code segment.
int j = 10;
int k = 8;
j += 2;
k += j;
System.out.print(j);
System.out.print(" ");
System.out.println(k);
What is printed when the code segment is executed?
AP CS A CH 1 Review
Quiz
•
Computers
•
10th - 12th Grade
•
Hard
Sammi McConnell
Used 20+ times
FREE Resource
27 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int j = 10;
int k = 8;
j += 2;
k += j;
System.out.print(j);
System.out.print(" ");
System.out.println(k);
What is printed when the code segment is executed?
2 2
2 10
10 8
12 12
12 20
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int x = 0;
x++;
x += 1;
x = x + 1;
x -= -1;
System.out.println(x);
What is printed when the code segment has been executed?
0
1
2
3
4
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int num = 5;
num *= 2;
num %= 6;
What is the value of num after the code segment is executed?
1
2
4
6
10
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int x = /* initial value not shown */;
int y = /* initial value not shown */;
int z = x;
z /= y;
z += 2;
Which of the following best describes the behavior of the code segment?
It sets z to 2.
It sets z to x.
It sets z to (1 / y) + 2.
It sets z to (x / y) + 2.
It sets z to (x + 2) / y.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment, which is intended to calculate the average of two quiz scores.
double avg = 15 + 20;
avg /= 2;
Which of the following best describes the behavior of the code segment?
The code segment stores 17 in avg because 17 is the result of the integer division of 35 by 2.
The code segment stores 18 in avg because 18 is the result of the integer division of 35 by 2.
The code segment stores 17.5 in avg because 17.5 is the result of the floating point division of 35.0 by 2.
The code segment does not compile because int values cannot be added to double values.
The code segment does not compile because a double value cannot be divided by an int value.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
int x = 4;
int y = 6;
x -= y;
y += x;
Which of the following best describes the behavior of the code segment?
The value of x and the value of y have not been changed.
Both the value of x and the value of y have been decreased.
Both the value of x and the value of y have been increased.
The value of x has been decreased and the value of y has been increased.
The value of x has been increased and the value of y has been decreased.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code segment.
double d = 0.25;
int i = 3;
double diff = d - i;
System.out.print((int)diff - 0.5);
What is printed as a result of executing the code segment?
-2
-2.5
-3
-3.25
Nothing is printed because an int cannot be subtracted from a double.
24 questions
SKT4 : Bab 1 : f) Tatasusunan & Subaturcara
Quiz
•
10th - 12th Grade
32 questions
2.16.1: Basic Java Review
Quiz
•
10th Grade
25 questions
Java Programming Quizz-GX
Quiz
•
9th - 12th Grade
24 questions
Javascript Basics
Quiz
•
7th Grade - University
22 questions
CodeHS AP CSP Unit 3 Review
Quiz
•
11th - 12th Grade
22 questions
AP CSA Algorithms Practise
Quiz
•
11th Grade
24 questions
AGAD: UNIT 4_C# & UNITY
Quiz
•
9th - 12th Grade
25 questions
Feb 20, 2025 AP CompSci - 1st Period
Quiz
•
12th Grade - University
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