A Magic Trick

Write a class named MagicTrick that takes three distinct single digits as arguments, and then performs the following tasks:

  1. Form the unique three-digit number from the digits provided, where the digits of the number formed strictly decrease from left to right.

  2. Find the number whose digits are the reverse of the number formed in the previous step.

  3. Given the two numbers formed above, subtract the smaller one from the larger one.

  4. Find the number whose digits are the reverse of the difference just found.

  5. Add the last two numbers together (i.e., the difference and the "reversed" difference)

The numbers found above should be printed in a manner similar to that shown in the sample run below.

Run this program several times, starting with different sets of three distinct single digit arguments -- do you notice anything seemingly magical? Why does this happen?

Sample run:

$ java MagicTrick 5 4 7
Number: 754
754 - 457 = 297
297 + 792 = 1089


To accomplish some of the tasks above, you may find the functions Math.min() and Math.max() very useful. For more information, see Commonly Used Methods of the java.lang.Math class.