-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphatonumeric.java
More file actions
88 lines (63 loc) · 2.08 KB
/
alphatonumeric.java
File metadata and controls
88 lines (63 loc) · 2.08 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
String numbers [] = {"one","two","three","four","five","six","seven","eight","nine"};
String places1[] = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
String places2[] = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
String places3[] = {"hundred"};
String places4[] = {"thousand"};
Scanner in = new Scanner(System.in);
int number = in.nextInt();
String str = String.valueOf(number);
int len = str.length();
String initial ="";
if(len == 1)
{
initial = numbers[str.charAt(0)-'0'-1];
}
else
if(len == 2)
{
if(str.charAt(str.length()-1)-'0' == 1)
{
initial = numbers[str.charAt(0)-'0'];
}
else
{
initial = places2[str.charAt(0)-'0'-1]+" "+numbers[str.charAt(1)-'0'-1];
}
}
if(len == 3)
{
initial = numbers[str.charAt(0)-'0'-1]+"hundred";
if(str.charAt(str.length()-2)-'0' == 1)
{
initial = initial+" "+numbers[str.charAt(1)-'0'-1];
}
else
{
initial = initial+" "+places2[str.charAt(1)-'0'-1]+" "+numbers[str.charAt(2)-'0'-1];
}
}
if(len == 4)
{
initial = numbers[str.charAt(0)-'0'-1]+"thousand";
initial = initial+" "+numbers[str.charAt(1)-'0'-1]+"hundred";
if(str.charAt(str.length()-2)-'0' == 1)
{
initial = initial+" "+numbers[str.charAt(2)-'0'-1];
}
else
{
initial = initial+" "+places2[str.charAt(2)-'0'-2]+" "+numbers[str.charAt(3)-'0'-1];
}
}
System.out.println(initial);
}
}