Numbers without Decimal Points in Java

By Barry Burd

Clearly, whole numbers have a role in this world. Therefore, in Java, you can declare a variable to store nothing but whole numbers. This listing shows a program that uses whole number variables.

public class ElevatorFitter {
    public static void main(String args[]) {
        int weightOfAPerson;
        int elevatorWeightLimit;
        int numberOfPeople;
        weightOfAPerson = 150;
        elevatorWeightLimit = 1400;
        numberOfPeople = 
            elevatorWeightLimit / weightOfAPerson;
        System.out.print("You can fit ");
        System.out.println(" people on the elevator.");

The story behind the program in the listing takes some heavy-duty explaining. So here goes:

You have a hotel elevator whose weight capacity is 1,400 pounds. One weekend, the hotel hosts the Brickenchicker family reunion. A certain branch of the Brickenchicker family has been blessed with identical dectuplets (ten siblings, all with the same physical characteristics). Normally, each of the Brickenchicker dectuplets weighs exactly 145 pounds.

But on Saturday, the family has a big catered lunch, and, because lunch included strawberry shortcake, each of the Brickenchicker dectuplets now weighs 150 pounds. Immediately after lunch, all ten of the Brickenchicker dectuplets arrive at the elevator at exactly the same time. (Why not? All ten of them think alike.) So, the question is, how many of the dectuplets can fit on the elevator?

Now remember, if you put one ounce more than 1,400 pounds of weight on the elevator, the elevator cable breaks, plunging all dectuplets on the elevator to their sudden (and costly) deaths.

The answer to the Brickenchicker riddle (the output of the program of the listing) is shown here.


At the core of the Brickenchicker elevator problem, you have whole numbers — numbers with no digits beyond the decimal point. When you divide 1,400 by 150, you get 9⅓, but you shouldn’t take the ⅓ seriously. No matter how hard you try, you can’t squeeze an extra 50 pounds worth of Brickenchicker dectuplet onto the elevator.

This fact is reflected nicely in Java. In the listing, all three variables (weightOfAPerson, elevatorWeightLimit, and numberOfPeople) are of type int. An int value is a whole number.

When you divide one int value by another (as you do with the slash in the listing), you get another int. When you divide 1,400 by 150, you get 9 — not 9⅓. You see this in the figure. Taken together, the following statements display 9 onscreen:

numberOfPeople = 
    elevatorWeightLimit / weightOfAPerson;