What primitive data type would you use to store the number of students in a classroom?
int – used for whole numbers like the number of students.
What is casting in Java?
Converting one data type to another manually using syntax like (int) or (double).
What is an API?
What is the result of 15 % 4?
3 – 15 divided by 4 leaves a remainder of 3.
How many dots appear on a pair of dice?
42
1+2+3+4+5+6 = 21
two dice = 42
What is the difference between a primitive and a reference data type in Java?
Primitive types store values directly (e.g., int, double); reference types (e.g., String, arrays) store memory addresses.
What is the result of casting the double 9.8 to an int?
9 – truncates the decimal part.
What does the following code output?
int x = 10;
x++;
System.out.println(x);
11 – x++ increases x after the statement.
What does the ++ operator do to a variable?
Increases the variable by 1.
Which is the only body part that is fully grown from birth?
Eyes
What keyword makes a variable constant and unable to be reassigned?
final – makes a variable unchangeable after initialization.
Why is casting not needed when assigning an int to a double?
Because it’s a automatic widening conversion and is allowed; no data is lost.
Trace this code and give the final value of y:
int x = 2;
int y = x * 3 + 1;
7 – 2 * 3 + 1 = 7
Which operators are evaluated first: *, /, %, +, or -?
*, /, and % are evaluated before + and -
Which country is credited with inventing ice cream?
China
What happens if you try to assign a String to an int variable?
Compile-time error – incompatible types.
What is the output of:
int x = (int)(3.7 + 0.5);
System.out.println(x);
AND what does this formula do?
4 – 3.7 + 0.5 = 4.2 → cast to int becomes 4.
This is the formula for ROUNDING A POSITIVE NUMBER.
What is the definition of an algorithm?
A step-by-step procedure for solving a problem
What is the output of:
System.out.println(8 % 3 * 2);
4
8 % 3 = 2;
2 * 2 = 4
Which country has the most islands?
Sweden (270,000)
What is the output of the following code?
int a = 5;
double b = 2.0;
System.out.println(a / b);
2.5 – int divided by double results in a double.
Identify the error:double x = 5 / 2; Why does this not result in 2.5?
3.5 – casting a 7 to a double results in double division that produces decimal result.
What will this code output?
int a = 5;
a += 3;
a--;
System.out.println(a);
7
a = 5 + 3 = 8;
a-- = 7
Evaluate the expression to find the value of result:
int result = 5 + 2 * 3 % 4;
7
2 * 3 = 6;
6 % 4 = 2;
5 + 2 = 7
What is the highest-rated film on IMDb as of January 1, 2024?
The Shawshank Redemption