Write a method printTwos that takes an
integer n as a parameter and that prints an expression composed of a single
odd number multiplied by twos that is equal to n. The twos should surround
the odd number with an equal number of twos on either side if possible. For
example, the call:
printTwos(80);
should produce the following output:
2 * 2 * 5 * 2 * 2
If the expression has an odd number of twos, then the "extra" two should
appear at the front of the expression. For example, the call:
printTwos(96);
should produce the following output:
2 * 2 * 2 * 3 * 2 * 2
If the number is odd to begin with, it should simply be printed. It is
possible that the odd number to print will be 1. For example, the following
calls:
printTwos(1);
System.out.println(); // to complete the line of output
printTwos(2);
System.out.println(); // to complete the line of output
printTwos(32);
System.out.println(); // to complete the line of output
should produce the following output:
1
2 * 1
2 * 2 * 2 * 1 * 2 * 2
You must exactly reproduce the format of the examples above. Your method
should throw an IllegalArgumentException if passed a value less than 1.
You may NOT use a while loop, for loop or do/while loop to solve this
problem; you must use recursion.
Write your solution to printTwos below.