Problem Statement
Given an int, how many LCD lines would show up on an old 8-digit calculator to represent the int?
Below are 10 digits and 'e' and '-' commonly used to display numbers on a calculator.
_ _ _ _ _ _ _ _ _ | | | _| _| |_| |_ |_ | |_| |_| |_ _ |_| | |_ _| | _| |_| | |_| _| |_
'0' has 6 lines, '1' has 2 lines, '2' has 5 lines
'3' has 5 lines, '4' has 4 lines, '5' has 5 lines
'6' has 6 lines, '7' has 3 lines, '8' has 7 lines
'9' has 6 lines, 'e' has 5 lines, and '-' has 1 line
The calculator only has 8 digits, and '-' takes up one of them: it can display "-1234567" or "12345678" but not "-12345678". If the number is too big to fit on the display, the calculator will display the error "0E" (consisting of 11 lines).
The calculator will never show leading 0s. For example, 1 will always show as '1', not as '000001', and 0 will show as '0' not as '00'. The calculator will never show '-0'. 0 will always show as '0' (6 lines).
Definition
- Class:
- LitLCD
- Method:
- numLines
- Parameters:
- int
- Returns:
- int
- Method signature:
- int numLines(int numToDisplay)
- (be sure your method is public)
Notes
- if the number is out of range for the calculator, you should return 11 (the number of LCD lines in 0E).
Constraints
- numToDisplay will be between -999,999,999 to 999,999,999, inclusive
Examples
17
Returns: 5
11118888
Returns: 36
99999999
Returns: 48
88888888
Returns: 56
100000000
Returns: 11
12345678
Returns: 37
12345678
Returns: 37
-1024
Returns: 18
4444
Returns: 16
111
Returns: 6
7171171
Returns: 17
654345
Returns: 29
98675
Returns: 27
55555
Returns: 25
333
Returns: 15
-7413759
Returns: 29
-12034102
Returns: 11
123484937
Returns: 11
8178234
Returns: 33
3467355
Returns: 33
-9231999
Returns: 37
999999997
Returns: 11
-1
Returns: 3
0
Returns: 6
-9999999
Returns: 43
-12345678
Returns: 11
999
Returns: 18
7
Returns: 3
999999999
Returns: 11
111111111
Returns: 11
42
Returns: 9
77777777
Returns: 24
-99999999
Returns: 11
-999999998
Returns: 11
-1234567
Returns: 31
-10000000
Returns: 11
-999999999
Returns: 11
-99999998
Returns: 11
-88888888
Returns: 11
12345679
Returns: 36
9999
Returns: 24
-7654321
Returns: 31
888
Returns: 21
546456
Returns: 30
1024
Returns: 17
_ _ | | | _| |_| | |_| |_ | 2 for '1', 6 for '0', 5 for '2', 4 for '4'
-1024
Returns: 18
12345678
Returns: 37
-999999999
Returns: 11
0
Returns: 6
111
Returns: 6
99999999
Returns: 48
100000000
Returns: 11