Problem Statement
A zeroless binary number is like an ordinary binary number, except that the possible digits are 1 and 2 instead of 0 and 1. The weights of the individual columns are still powers of two, as usual. For example, the zeroless binary number "2121" has '2' in the 8's column, '1' in the 4's column, '2' in the 2's column, and '1' in the 1's column (all quotes for clarity only). Its value is therefore 2*8 + 1*4 + 2*2 + 1*1 = 25.
Write a method that converts an int n into zeroless binary format.
Definition
- Class:
- Zeroless
- Method:
- convert
- Parameters:
- int
- Returns:
- String
- Method signature:
- String convert(int n)
- (be sure your method is public)
Constraints
- n is between 1 and 1000000, inclusive.
Examples
25
Returns: "2121"
The example above.77
Returns: "112221"
77 = 1*32 + 1*16 + 2*8 + 2*4 + 2*2 + 1*11
Returns: "1"
126
Returns: "222222"
1000000
Returns: "2221211112112111112"