All Flashcards
How is the modulo operator used in scheduling tasks?
To cycle through a set of tasks or resources, assigning each task a number and using modulo to determine the resource to use.
How is integer division used in array indexing?
To calculate the index of an element in a multi-dimensional array when the array is stored in a linear fashion.
How are increment/decrement operators used in loops?
To update loop counters, controlling the number of iterations and accessing different elements in a data structure.
How are expressions and assignment statements used in updating game scores?
Expressions calculate the new score based on game events, and assignment statements update the score variable.
How is order of operations important in financial calculations?
Ensures calculations like interest, taxes, and discounts are performed in the correct sequence, leading to accurate results.
How are data types used in scientific simulations?
Choosing appropriate data types (int, double) affects precision and memory usage when simulating physical phenomena.
How is the modulo operator used in cryptography?
In encryption algorithms, the modulo operator is used for performing modular arithmetic, which is essential for secure communication.
How are assignment statements used in updating the state of a program?
Assignment statements are used to update variables that represent the state of a program, such as the current user, the current level, or the current mode.
How is integer division used in image processing?
Integer division can be used to downsample images or to divide an image into smaller regions for processing.
How are increment/decrement operators used in data analysis?
Increment/decrement operators can be used to update counters or to iterate through data sets.
What is the value of a
after: int a = 5 / 2;
?
a is 2.
What is the value of b
after: double b = 5 / 2.0;
?
b is 2.5.
What is the value of c
after: int c = 10 % 3;
?
c is 1.
What is the value of d
after: int d = 3 + 4 / 3 * (4-1);
?
d is 6.
What is the value of e
after: double e = (3 * 5 / 2) / (2.0 + 8);
?
e is 0.7.
What is the value of f
after: int f = 4 % 3 + 2 * 5 / 4;
?
f is 3.
What is the value of g
after: int g = (3 * 5 / 2) / (2 + 8);
?
g is 0.
What is the output of: int x = 7; int y = x++; System.out.println(y);
?
7
What is the output of: int x = 7; int y = ++x; System.out.println(y);
?
8
What is the value of result
after: int a = 5; double b = 2.5; double result = a + b;
?
result is 7.5
What is an assignment operator?
Evaluates the expression on the right and stores the result in the variable on the left.
What is integer division?
Division that returns only the whole number quotient (truncates the decimal).
What is double division?
Division that returns the actual quotient as a decimal.
What is the modulo operator?
The modulo operator (%) gives you the remainder of a division.
What is PEMDAS/BODMAS?
The standard order of mathematical operations: Parentheses, Exponents, Multiplication and Division, Addition and Subtraction.
What is the int
data type?
A data type representing integers (whole numbers).
What is the double
data type?
A data type representing floating-point numbers (numbers with decimal points).
What is a variable?
A named storage location in memory that can hold a value.
What is an expression?
A combination of variables, operators, and values that evaluates to a single value.
What is truncation?
Removing the decimal portion of a number, effectively rounding it down to the nearest integer.