-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElara.java
More file actions
33 lines (33 loc) · 1.01 KB
/
Elara.java
File metadata and controls
33 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class Elara
{
static String ones[]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
static String tens[]={"","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
static String f(int n)
{
if(n==0)
return "";
if(n<20)
return ones[n];
if(n<100)
return tens[n/10]+" "+f(n%10);
if(n<1000)
return f(n/100)+" Hundred "+f(n%100);
if(n<1e6)
return f(n/1000)+" Thousand "+f(n%1000);
if(n<1e9)
return f(n/1000000)+" Million "+f(n%1000000);
return f(n/1000000000)+" Billion "+f(n%1000000000);
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
if(n<0 || n>((2e31)-1))
{
System.out.println("Invalid");
return;
}
System.out.println(n==0?"Zero":f(n).trim().replaceAll(" +"," "));
}
}