0
0
Javaprogramming~20 mins

Primitive data types in Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Primitive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
    }
}
A3.5
B3.6
C3
D3.0
Attempts:
2 left
💡 Hint
Remember that dividing two integers results in an integer before assignment.
Predict Output
intermediate
2: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);
    }
}
A65
BC
C67
D2
Attempts:
2 left
💡 Hint
Remember that char is treated as a number in arithmetic.
Predict Output
advanced
2: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);
    }
}
Atrue
Bfalse
Cnull
DCompilation error
Attempts:
2 left
💡 Hint
Evaluate the boolean expression step by step.
Predict Output
advanced
2: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);
    }
}
A1.234567
B1.2345679
C1.23456789
D1.234568
Attempts:
2 left
💡 Hint
Float has less precision than double.
🧠 Conceptual
expert
2:00remaining
Memory size of primitive types
Which primitive data type in Java uses the most memory?
Adouble
Bint
Clong
Dfloat
Attempts:
2 left
💡 Hint
Think about the number of bytes each type uses.