Labels

.NET Job Questions About Java Absract class Abstract class Abstract Class and Interface Aggregation ajax aop apache ofbiz Apache ofbiz tutrial Association authentication autocad basics batch Binary Tree bootstrap loader in java build Builder design pattern C++ Job Questions caching CallableStatement in java certifications Chain of responsibility Design pattern charts check parentheses in a string Classes classloader in java classloading concept code quality collage level java program Composition concurrency Concurrency Tutorial Converting InputStream to String Core Java core java concept core java interview questions Core Java Interview Questions Core Java Questions core java tutorial CyclicBarrier in Java data structures database Database Job Questions datetime in c# DB Db2 SQL Replication deserialization in java Design Patterns designpatterns Downloads dtd Eclipse ejb example/sample code exception handling in core java file handling injava File I/O vs Memory-Mapped Filter first program in spring flex Garbage Collection Generics concept in java grails groovy and grails Guice Heap hibernate Hibernate Interview Questions how-to IBM DB2 IBM DB2 Tutorial ide immutable Interceptor Interface interview Interview Questions for Advanced JAVA investment bank j2ee java JAVA Code Examples Java 7 java changes java class loading JAVA Classes and Objects Java Classloader concept Java classloading concept java cloning concept java collection Java collection interview questions Java Collections java concurrency Java CountDownLatch java definiton Java design pattern Java EE 5 Java EE 6 Java Exceptions Java file Java Garbage Collection Java generics Java Glossary java hot concept java immutable concept Java Interface Java interview Question java interview question 2012 java interview question answer Java Interview Questions Java Interview Questions and Answers java interview topic java investment bank Java Job Questions java multithreading java multithreading concept java new features Java Packages java proxy object java questions Java Serialization Java serialization concept java serialization interview question java session concept java string Java Swings Questions java synchronization java threading Java Threads Questions java tutorial java util; java collections; java questions java volatile java volatile interview question Java Wrapper Classes java.java1.5 java.lang.ClassCastException JavaNotes javascript JAX-WS jdbc JDBC JDBC Database connection jdk 1.5 features JDK 1.5 new features Concurrent HashMap JMS interview question JMS tutorial job JSESSIONID concept JSESSIONID interview Question JSF jsp JSP Interview Question JSP taglib JSTL with JSP Junit Junit Concept Junit interview question.Best Practices to write JUnit test cases in Java JVM Linux - Unix tutorial Marker Interfaces MD5 encryption and decryption messaging MNC software java interview question musix NCR java interview question Networking Job Questions news Object Serialization Objects ojdbc14.jar OOP Oracle Oracle SQL Query for two timestamp difference orm own JavaScript function call in Apache ofbiz Packages Palm Apps patterns pdf persistence Portal Portlet Spring Integration Prime number test in java programs Rails Reboot remote computers REST Ruby Sample application schema SCJP security Senior java developer interviews servlet3 servlets session tracking singleton design pattern Spring Spring 2.5 Framework spring ebook Spring framework concept spring MVC spring pdf Spring Security Spring Security interview questions SQL SQL performance SQL Query to create xml file Sql Query tuning ssis and ssrs StAX and XML string concept string immutable string in java strings struts Struts2 Struts2 integration synchronization works in java Technical Interview testing tips Tomcat top Tutorial Volatile in deep Volatile working concept web Web Developer Job Questions web services weblogic Weblogic Application Server websphere what is JSESSIONID xml XML parsing in java XML with Java xslt


Monday 8 July 2013

Convert numbers to word as per Indian number system in java

This java program converts the number to its equivalent word representation according to indian numbering system. Eg. Lakhs, Crores etc..This program works upto 999999999.


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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
import java.util.*;

public class NumtoWord {
public static void main(String[] args) {
String a;
Scanner s = new Scanner(System.in);
System.out.print("Enter a Number : ");
a = s.next();
int b = a.length();
String str[] = { "1", "One", "2", "Two", "3", "Three", "4", "Four",
"5", "Five", "6", "Six", "7", "Seven", "8", "Eight", "9",
"Nine", "10", "Ten", "11", "Eleven", "12", "Twelve", "13",
"Thirteen", "14", "Forteen", "15", "Fifteen", "16", "Sixteen",
"17", "Seventeen", "18", "Eighteen", "19", "Nineteen", "20",
"Twenty", "30", "Thirty", "40", "Fourty", "50", "Fifty", "60",
"Sixty", "70", "Seventy", "80", "Eighty", "90", "Ninty", "100",
"Hundred" };
System.out.println("");
if (b == 9) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s4 = a.substring(3, 4);
String s5 = a.substring(4, 5);
String s6 = a.substring(5, 6);
String s7 = a.substring(6, 7);
String s8 = a.substring(7, 8);
String s9 = a.substring(8, 9);
String s10 = a.substring(0, 2);
String s11 = a.substring(2, 4);
String s12 = a.substring(4, 6);
String s14 = a.substring(7, 9);
{
if (s10.equals("00"))
System.out.print("");
else if (s1.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print("\n" + str[r + 1] + " Crore ");
} else {
{
for (int i = 0; i <= 40; i++)
if (str[i].equals(s1))
System.out.print("\n" + str[i + 37] + " ");
}
{
if (s2.equals("0")) {
System.out.print("Crore ");
} else
for (int j = 0; j <= 40; j++) {
if (str[j].equals(s2))
System.out.print(str[j + 1] + " Crore ");
}
}
}
}
{
if (s11.equals("00"))
System.out.print("");
else if (s3.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s11))
System.out.print(str[r + 1] + " Lacks ");
} else {
{
for (int k = 0; k <= 38; k++)
if (str[k].equals(s3))
System.out.print(str[k + 37] + " ");
}
{
if (s4.equals("0")) {
System.out.print("Lacks ");
} else
for (int l = 0; l <= 38; l++) {
if (str[l].equals(s4))
System.out.print(str[l + 1] + " Lacks ");
}
}
}
}
{
if (s12.equals("00"))
System.out.print("");
else if (s5.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s12))
System.out.print(str[r + 1] + " Thousand ");
} else {
{
for (int m = 0; m <= 38; m++)
if (str[m].equals(s5))
System.out.print(str[m + 37] + " ");
}
{
if (s6.equals("0")) {
System.out.print("Thousand ");
} else
for (int n = 0; n <= 38; n++) {
if (str[n].equals(s6))
System.out.print(str[n + 1] + " Thousand ");
}
}
}
}
{
for (int o = 0; o <= 40; o++)
if (str[o].equals(s7))
System.out.print(str[o + 1] + " Hundred ");
}
{
if (s14.equals("00"))
System.out.print("");
else if (s8.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s14))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s8))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s9))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 8) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s4 = a.substring(3, 4);
String s5 = a.substring(4, 5);
String s6 = a.substring(5, 6);
String s7 = a.substring(6, 7);
String s8 = a.substring(7, 8);
String s10 = a.substring(1, 3);
String s11 = a.substring(3, 5);
String s12 = a.substring(6, 8);
{
if (s1.equals("0"))
System.out.print("");
else
for (int i = 0; i <= 40; i++)
if (str[i].equals(s1))
System.out.print("\n" + str[i + 1] + " Crore ");
}
{
if (s10.equals("00"))
System.out.print("");
else if (s2.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1] + " Lacks ");
} else {
{
for (int k = 0; k <= 38; k++)
if (str[k].equals(s2))
System.out.print(str[k + 37] + " ");
}
{
if (s3.equals("0")) {
System.out.print("Lacks ");
} else
for (int l = 0; l <= 38; l++) {
if (str[l].equals(s3))
System.out.print(str[l + 1] + " Lacks ");
}
}
}
}
{
if (s11.equals("00"))
System.out.print("");
else if (s4.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s11))
System.out.print(str[r + 1] + " Thousand ");
} else {
{
for (int m = 0; m <= 38; m++)
if (str[m].equals(s4))
System.out.print(str[m + 37] + " ");
}
{
if (s5.equals("0")) {
System.out.print("Thousand ");
} else
for (int n = 0; n <= 38; n++) {
if (str[n].equals(s5))
System.out.print(str[n + 1] + " Thousand ");
}
}
}
}
{
for (int o = 0; o <= 40; o++)
if (str[o].equals(s6))
System.out.print(str[o + 1] + " Hundred ");
}
{
if (s12.equals("00"))
System.out.print("");
else if (s7.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s12))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s7))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s8))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 7) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s4 = a.substring(3, 4);
String s5 = a.substring(4, 5);
String s6 = a.substring(5, 6);
String s7 = a.substring(6, 7);
String s10 = a.substring(0, 2);
String s11 = a.substring(2, 4);
String s12 = a.substring(5, 7);
{
if (s10.equals("00"))
System.out.print("");
else if (s1.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1] + " Lacks ");
} else {
{
for (int k = 0; k <= 38; k++)
if (str[k].equals(s1))
System.out.print(str[k + 37] + " ");
}
{
if (s2.equals("0")) {
System.out.print("Lacks ");
} else
for (int l = 0; l <= 38; l++) {
if (str[l].equals(s2))
System.out.print(str[l + 1] + " Lacks ");
}
}
}
}
{
if (s11.equals("00"))
System.out.print("");
else if (s3.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s11))
System.out.print(str[r + 1] + " Thousand ");
} else {
{
for (int m = 0; m <= 38; m++)
if (str[m].equals(s3))
System.out.print(str[m + 37] + " ");
}
{
if (s4.equals("0")) {
System.out.print("Thousand ");
} else
for (int n = 0; n <= 38; n++) {
if (str[n].equals(s4))
System.out.print(str[n + 1] + " Thousand ");
}
}
}
}
{
for (int o = 0; o <= 40; o++)
if (str[o].equals(s5))
System.out.print(str[o + 1] + " Hundred ");
}
{
if (s12.equals("00"))
System.out.print("");
else if (s6.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s12))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s6))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s7))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 6) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s4 = a.substring(3, 4);
String s5 = a.substring(4, 5);
String s6 = a.substring(5, 6);
String s10 = a.substring(1, 3);
String s11 = a.substring(4, 6);

{
if (s1.equals("0"))
System.out.print("");
else {
for (int j = 0; j <= 40; j++)
if (str[j].equals(s1))
System.out.print(str[j + 1] + " Lacks ");
}
}
{
if (s10.equals("00"))
System.out.print("");
else if (s2.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1] + " Thousand ");
} else {
{
for (int m = 0; m <= 40; m++)
if (str[m].equals(s2))
System.out.print(str[m + 37] + " ");
}
{
if (s3.equals("0")) {
System.out.print("Thousand ");
} else
for (int n = 0; n <= 38; n++) {
if (str[n].equals(s3))
System.out.print(str[n + 1] + " Thousand ");
}
}
}
}
{
if (s4.equals("0"))
System.out.print("");
else {
for (int o = 0; o <= 40; o++)
if (str[o].equals(s4))
System.out.print(str[o + 1] + " Hundred ");
}
}
{
if (s11.equals("00"))
System.out.print("");
else if (s5.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s11))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s5))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s6))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 5) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s4 = a.substring(3, 4);
String s5 = a.substring(4, 5);
String s10 = a.substring(0, 2);
String s11 = a.substring(3, 5);
{
if (s10.equals("00"))
System.out.print("");
else if (s1.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1] + " Thousand ");
} else {
{
for (int m = 0; m <= 38; m++)
if (str[m].equals(s1))
System.out.print(str[m + 37] + " ");
}
{
if (s2.equals("0")) {
System.out.print("Thousand ");
} else
for (int n = 0; n <= 38; n++) {
if (str[n].equals(s2))
System.out.print(str[n + 1] + " Thousand ");
}
}
}
}
{
for (int o = 0; o <= 40; o++)
if (str[o].equals(s3))
System.out.print(str[o + 1] + " Hundred ");
}
{
if (s11.equals("00"))
System.out.print("");
else if (s4.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s11))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s4))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s5))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 4) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s4 = a.substring(3, 4);
String s10 = a.substring(2, 4);
{
if (s1.equals("0"))
System.out.print("");
else {
for (int j = 0; j <= 40; j++)
if (str[j].equals(s1))
System.out.print(str[j + 1] + " Thousand ");
}
}
{
if (s2.equals("0"))
System.out.print("");
else {
for (int o = 0; o <= 40; o++)
if (str[o].equals(s2))
System.out.print(str[o + 1] + " Hundred ");
}
}
{
if (s10.equals("00"))
System.out.print("");
else if (s3.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s3))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s4))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 3) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s3 = a.substring(2, 3);
String s10 = a.substring(1, 3);
{
if (s1.equals("0"))
System.out.print("");
else {
for (int o = 0; o <= 40; o++)
if (str[o].equals(s1))
System.out.print(str[o + 1] + " Hundred ");
}
}
{
if (s10.equals("00"))
System.out.print("");
else if (s2.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s2))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s3))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 2) {
String s1 = a.substring(0, 1);
String s2 = a.substring(1, 2);
String s10 = a.substring(0, 2);
{
if (s10.equals("00"))
System.out.print("");
else if (s1.equals("1")) {
for (int r = 0; r <= 40; r++)
if (str[r].equals(s10))
System.out.print(str[r + 1]);
System.out.print("\n");
} else {
for (int p = 0; p <= 40; p++)
if (str[p].equals(s1))
System.out.print(str[p + 37]);
for (int q = 0; q <= 40; q++) {
if (str[q].equals(s2))
System.out.print(" " + str[q + 1]);
}
}
System.out.print("\n");
}
} else if (b == 1) {
String s1 = a.substring(0, 1);
for (int q = 0; q <= 40; q++)
if (str[q].equals(s1))
System.out.print(" " + str[q + 1]);
}
System.out.println("\n");
}
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...