Practice problems

Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.

Showing 1–20 of 22 problems

Jv

Your first Java program

What appears in the console?

Beginner
Jv

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.

Beginner
Jv

Strings and text comparisons

Which comparison checks that their text matches?

Beginner
Jv

Reading and validating console input

What number does parseInt produce after trim?

Beginner
Jv

Conditions and loops

Add only the even numbers from 1 through the input limit, inclusive.

Beginner
Jv

Methods and return values

Add the areas of the listed rectangles. Each pair lists its width and height.

Beginner
Jv

Arrays and ArrayList

Read the last title in each list. If the list has no titles, return "Empty".

Beginner
Jv

Enums and fixed choices

Can a caller assign the unrelated string shipped directly to an enum variable?

Beginner
Jv

Classes and objects

Two counters start independently. Predict both values after calling increment twice on the first counter.

Intermediate
Jv

Constructors and encapsulation

Where should you reject an initial balance of -1?

Intermediate
Jv

Interfaces and polymorphism

What string does this implementation return?

Intermediate
Jv

Generics and type parameters

Why does the compiler flag this line?

Intermediate
Jv

Maps and sets

Which value does get("a") return?

Intermediate
Jv

Exceptions and resource handling

Why does the conversion fail?

Intermediate
Jv

Lambdas and stream pipelines

What values appear in the resulting list?

Intermediate
Jv

Records and value equality

What boolean is produced?

Intermediate
Jv

Class composition and inheritance

How can it use either rule without being a discount rule itself?

Intermediate
Jv

Paths and text files

Which file is selected?

Intermediate
Jv

Threads, shared state, and atomicity

What total should two successful atomic increments leave?

Advanced
Jv

Combining asynchronous results

What value does the transformed future hold?

Advanced