Homework 5,
T-H section, assigned MAR. 25 due TUE APR 1 at 11:59pm
M-W section, assigned MAR. 26 due WED APR 3 at 11:59pm

### Part A

Write a program in which the main method calls a method with the heading public static int subtract(int num) that takes a three digit integer num and does the following

• Decomposes it into three digits, digit1, digit2 and digit3 that constitute the three-digit number..
• Using Math.max() and Math.min() determines the digits with the maximum and minimum value and assign them to maxDigit and minDigit respectively.
• Using Prog5.java from MAR 11 or Prog5.java from MAR 12, determine the middle digit and assigns it to midDigit.
• Constructs an integer, ascend in which these digits appear in ascending order. For instance, if the original value of num was 673, the constructed integer would be 367.
• Repeats the last step but this time produces the digits in descending order. So in our example, it would produce 763. It assigns this to descend.
• Prints these two values.
• Subtracts these two numbers (descend - ascend) and returns this value in the method.

### Part B

Write another program that contains method subtract and calls it in a while loop. The loop executes until the method returns a value that doesn't change, i.e., 495. This is somewhat tricky. Here are some suggestions:

• To simplify this, remove the print statments from method subtract.
• Assign a number, let's say 231 to a variable called number and 0 to one called previous before the while loop.
• In the loop, set previous to the value of number (we say that previous chases number) and obtain a new value for number.
• Choose the boolean expression in the while statement so that the loop eventually termintes.
• Your program should print all the values of number.

Hand in only part B