Put dependent declarations in a legal order

A packing program calculates how many boxes it can fill after reserving some items. Arrange these four Java statements in the only order that compiles when they appear consecutively inside the same method block. None of these variable names is declared elsewhere, and you may not change any statement.

  1. 1.

    int total = 48;

  2. 2.

    int available = total - reserved;

  3. 3.

    int reserved = total / 4;

  4. 4.

    int boxes = available / 6;

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Variable Declarations and Scope in Java Questions: