Challenge - 5 Problems
Primitive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of integer division and casting
What is the output of this Java code snippet?
Java
public class Main { public static void main(String[] args) { int a = 7; int b = 2; double c = a / b; System.out.println(c); } }
Attempts:
2 left
💡 Hint
Remember that dividing two integers results in an integer before assignment.
✗ Incorrect
In Java, dividing two integers performs integer division, so 7 / 2 equals 3. Assigning this to a double variable converts 3 to 3.0.
❓ Predict Output
intermediate2:00remaining
Output of char arithmetic
What is the output of this Java code?
Java
public class Main { public static void main(String[] args) { char ch = 'A'; int result = ch + 2; System.out.println(result); } }
Attempts:
2 left
💡 Hint
Remember that char is treated as a number in arithmetic.
✗ Incorrect
The char 'A' has ASCII value 65. Adding 2 results in 67, which is printed as an int.
❓ Predict Output
advanced2:00remaining
Output of boolean logic with primitives
What is the output of this Java program?
Java
public class Main { public static void main(String[] args) { boolean a = true; boolean b = false; boolean c = a && !b || b; System.out.println(c); } }
Attempts:
2 left
💡 Hint
Evaluate the boolean expression step by step.
✗ Incorrect
a is true, b is false, so !b is true. Then a && !b is true && true = true. true || false is true.
❓ Predict Output
advanced2:00remaining
Output of float precision and casting
What is the output of this Java code?
Java
public class Main { public static void main(String[] args) { float f = 1.23456789f; double d = f; System.out.println(d); } }
Attempts:
2 left
💡 Hint
Float has less precision than double.
✗ Incorrect
The float value loses precision beyond 7 digits. When assigned to double, it keeps the float precision, printing approximately 1.2345679.
🧠 Conceptual
expert2:00remaining
Memory size of primitive types
Which primitive data type in Java uses the most memory?
Attempts:
2 left
💡 Hint
Think about the number of bytes each type uses.
✗ Incorrect
double uses 8 bytes (64 bits), which is more than int (4 bytes) and float (4 bytes). Although long and double both use 8 bytes, double stores floating-point numbers, so it is considered the largest in terms of precision.