File tree Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+ public class Main {
4
+ public static void main (String [] args ) throws IOException {
5
+ File file = new File (args [0 ]);
6
+ BufferedReader br = new BufferedReader (new FileReader (file ));
7
+ String line ;
8
+ Main m = new Main ();
9
+ while ((line = br .readLine ()) != null ) {
10
+ int i = Integer .parseInt (line );
11
+ if (i ==0 ) {
12
+ System .out .println ("ZeroDollars" );
13
+ }
14
+ else {
15
+ System .out .println (m .word (i ) +"Dollars" );
16
+ }
17
+ }
18
+ br .close ();
19
+ }
20
+ String word (int i ) {
21
+ Map <Integer , String > m = new HashMap <Integer , String >();
22
+ m .put (1 , "One" );
23
+ m .put (2 , "Two" );
24
+ m .put (3 , "Three" );
25
+ m .put (4 , "Four" );
26
+ m .put (5 , "Five" );
27
+ m .put (6 , "Six" );
28
+ m .put (7 , "Seven" );
29
+ m .put (8 , "Eight" );
30
+ m .put (9 , "Nine" );
31
+ m .put (10 , "Ten" );
32
+ m .put (11 , "Eleven" );
33
+ m .put (12 , "Twelve" );
34
+ m .put (13 , "Thirteen" );
35
+ m .put (14 , "Fourteen" );
36
+ m .put (15 , "Fifteen" );
37
+ m .put (16 , "Sixteen" );
38
+ m .put (17 , "Seventeen" );
39
+ m .put (18 , "Eighteen" );
40
+ m .put (19 , "Nineteen" );
41
+ m .put (20 , "Twenty" );
42
+ m .put (30 , "Thirty" );
43
+ m .put (40 , "Forty" );
44
+ m .put (50 , "Fifty" );
45
+ m .put (60 , "Sixty" );
46
+ m .put (70 , "Seventy" );
47
+ m .put (80 , "Eighty" );
48
+ m .put (90 , "Ninety" );
49
+ if (i > 0 && i <= 20 ) {
50
+ return m .get (i );
51
+ }
52
+ if (i > 20 && i < 100 ) {
53
+ int y = i -(i %10 );
54
+ int z = i %10 ;
55
+ return m .get (y )+this .word (z );
56
+ }
57
+ if (i >= 100 && i < 1000 ) {
58
+ int y = i -(i %100 );
59
+ int z = i %100 ;
60
+ return m .get (y /100 )+"Hundred" +this .word (z );
61
+ }
62
+ if (i >= 1000 && i < 10000 ) {
63
+ int y = i -(i %1000 );
64
+ int z = i %1000 ;
65
+ return m .get (y /1000 )+"Thousand" +this .word (z );
66
+ }
67
+ if (i >= 10000 && i < 1000000 ) {
68
+ int y = i -(i %1000 );
69
+ int z = i %1000 ;
70
+ return this .word (y /1000 )+"Thousand" +this .word (z );
71
+ }
72
+ if (i >= 1000000 && i < 1000000000 ) {
73
+ int y = i -(i %1000000 );
74
+ int z = i %1000000 ;
75
+ return this .word (y /1000000 )+"Million" +this .word (z );
76
+ }
77
+ return "" ;
78
+ }
79
+ }
You can’t perform that action at this time.
0 commit comments