Practice problems
Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.
Showing 21–40 of 145 problems
Decorators and function wrapping
What value reaches its caller?
Context managers and resource cleanup
Does leaving the block still close the file?
Async tasks and cancellation
Can the timer waits overlap?
Profiling and memory use
Which area is the strongest first candidate for optimization?
Your first Java program
What appears in the console?
Variables and types
Print the number of full pairs and the remaining tickets as two lines. For 5 tickets, there are 2 pairs and 1 ticket left.
Strings and text comparisons
Which comparison checks that their text matches?
Reading and validating console input
What number does parseInt produce after trim?
Conditions and loops
Add only the even numbers from 1 through the input limit, inclusive.
Methods and return values
Add the areas of the listed rectangles. Each pair lists its width and height.
Arrays and ArrayList
Read the last title in each list. If the list has no titles, return "Empty".
Enums and fixed choices
Can a caller assign the unrelated string shipped directly to an enum variable?
Classes and objects
Two counters start independently. Predict both values after calling increment twice on the first counter.
Constructors and encapsulation
Where should you reject an initial balance of -1?
Interfaces and polymorphism
What string does this implementation return?
Generics and type parameters
Why does the compiler flag this line?
Maps and sets
Which value does get("a") return?
Exceptions and resource handling
Why does the conversion fail?
Lambdas and stream pipelines
What values appear in the resulting list?
Records and value equality
What boolean is produced?