-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigits to Words
More file actions
105 lines (93 loc) · 2.29 KB
/
Digits to Words
File metadata and controls
105 lines (93 loc) · 2.29 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Import java.util.*;
Class ISCprac2011q01{
Public static void main(String args[])
Throws InputMismatchException{
Scanner scan=new Scanner(System.in);
Int n;
System.out.println(“Enter a number less than 1000”);
N=scan.nextInt();
If(n>=1000)
{
System.out.println(“OUT OF RANGE”);
}else{
String result,h=””,t=””,o=””;
Int a,b,c;
String ones[]={“one”, “two”,”three”,”four”,”five”,
“six”,”seven”,”eight”,”nine”};
String teens[]={“eleven”,”twelve”,”thirteen”,”fourteen”,
“fifteen”,”sixteen”,”seventeen”,”eighteen”,”nineteen”};
String tens[]={“ten”,”twenty”,”thirty”,”forty”,”fifty”,
“sixty”,”seventy”,”eighty”,”ninety”};
If(n>=100 && n<1000){
A=n/100;
Result=ones[a-1]+” hundred”;
N=n%100;
}
If(n%10==0 && n!=0){
A=n/10;
If(result!=null){
Result+=” and “;
Result+=tens[a-1];
}else{
Result=tens[a-1];
}
N=n%10;
}
If(n>20 && n<100){
A=n/10;
B=n%10;
If(result!=null){
Result+=” and “;
Result+=tens[a-1]+” “+ones[b-1];
}else{
Result=tens[a-1]+” “+ones[b-1];
}
}
If(n>10 && n<20){
A=n%10;
If(result!=null){
Result+=” and “;
Result+=teens[a-1];
}else{
Result=teens[a-1];
}
}
If(n<10 && n!=0){
If(result!=null)
{
Result+=” and “;
Result+=ones[n-1];
}else{
Result=ones[n-1];
}
OR
A=n/100;
If(n>100){
N=n%100;
}
B=n/10;
C=n%10;
If(a!=0){
H=ones[a-1]+” hundred”;
}
If(b==0 && c!=0){
O=ones[c-1];
}
Else if(c==0 && b!=0){
T=tens[b-1];
}
Else if(b==1){
T=teens[c-1];
}
Else if(b!=0 && c!=0){
T=tens[b-1]+” “+ones[c-1];
}
If(b==0 && c==0)
Result=h;
Else if(a==0)
Result=t+” “+o;
Else
Result=h+” and “+t+” “+o;
System.out.println(“\n”+result.toUpperCase());
}
}