
Primitive Types in Java Programming -Unit 1- AP CSA
Authored by Corey Woodring
Computers
9th - 12th Grade

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
64 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Vincent is organizing his desk and wants to label a box to store his pens. In programming, what is a variable similar to?
A variable is a named storage location that holds a value.
A variable is a function in programming.
A variable is a type of loop in programming.
A variable is a mathematical equation.
Answer explanation
A variable is a named storage location that holds a value, allowing programmers to store and manipulate data. The other options incorrectly describe functions, loops, or mathematical equations.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Jacob and Gabriel are learning Java. Which of the following options are primitive data types in Java?
integer, boolean, double, String
integer, boolean, double
integer, boolean, double, String, Scanner
integer, boolean, double, String, Object
Answer explanation
In Java, the primitive data types include integer (int), boolean, and double. String and Object are reference types, not primitive. Therefore, the correct choice is 'integer, boolean, double'.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Eric is learning Java and wants to declare a variable to store his age. What is the correct syntax for declaring a variable in Java?
var myVar;
myVariable = int;
int myVariable;
declare myVariable;
Answer explanation
The correct syntax for declaring a variable in Java is 'int myVariable;'. This specifies the type (int) and the variable name (myVariable), which is the standard way to declare variables in Java.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Jeremy is writing a program to calculate the average score of his class. He needs to store whole numbers for the number of students and decimal numbers for the average score. What data types should he use for these variables?
int is used for storing characters while double is used for storing strings.
int is used for whole numbers while double is used for decimal numbers.
int is used for decimal numbers while double is used for whole numbers.
int is used for positive numbers while double is used for negative numbers.
Answer explanation
The correct choice states that 'int' is for whole numbers (e.g., 1, 2, 3) and 'double' is for decimal numbers (e.g., 1.5, 2.75). This distinction is crucial in programming for handling different types of numerical data.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Eric is writing a program to manage his book collection. What is the purpose of a variable in his program?
To store and manipulate data in a program.
To execute functions in a program.
To display data in a program.
To control the flow of a program.
Answer explanation
The purpose of a variable is to store and manipulate data in a program. It allows programmers to hold values that can be changed and used throughout the code, making it essential for data handling.
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
During a programming class, Brennan and Om were discussing a code segment.
System.out.println("W");
System.out.println("X");
System.out.print("Y");
System.out.print("Z");
What is printed as a result of executing the code segment?
WXYZ
W
XYZ
WX
YZ
W
X
YZ
W
X
Y
Z
Answer explanation
The code prints 'W' and 'X' on separate lines due to println, and 'Y' and 'Z' on the same line due to print. Thus, the output is 'W' on one line, 'X' on the next, and 'YZ' on the same line, matching the choice 'W', 'X', 'YZ'.
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Richard and Eric are working on a project that involves calculating ratios.
int x = 10;
int y = 20;
/* missing code */
System.out.print(top / bottom);
Which of the following replacements for /* missing code */ will cause an ArithmeticException to occur?
I. int top = x - y;int bottom = y - x;
II.int top = 2 * x;int bottom = y - top;
III. int top = x + y;int bottom = 2 * top;
I. only
II. only
III. only
I. and II.
II. and III.
Answer explanation
In option II, top = 2 * x (20) and bottom = y - top (0), leading to division by zero, which causes an ArithmeticException. Options I and III do not result in zero for bottom, so they do not cause exceptions.
Access all questions and much more by creating a free account
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?