Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Programming

Tutorial: Three for Two

 

The function Math.min gives the minimum of exactly two numbers. if we want to calculate the minimum or three numbers or four numbers we can get the minimum of a minimum.

If we want to find the minimum of more numbers there are other techniques.

1. Discount on Three for Two


Big

There is a "three for the price of two" offer on books. If three books are purchased there is a discount equal to the cheapest.

Use the Math.min function to find the smallest of three numbers.

min of three numbers

2. Price of Three for Two


Big

There is a "three for the price of two" offer on books. If three books are purchased there is a discount equal to the cheapest.

Find the cost to the customer of three books. That is, the price of the two most expensive books.

Hint: