# International System of Numeration

**The international system** is followed by most of the countries of the world. In this system, a number is split up into groups or periods.In the Inter-national System of Numeration, we use ones, tens, hundreds, thousands, millions and billions.

**The 1st period consists of —> ones, tens and hundred.**

The 2nd period consists of —> thousand, 10 thousand and 100 thousands.

The 3rd period consists of —> million, 10 million and 100 million.

The 4th period consists of —> billion, 10 billion and 100 billion.

One million is a thousand thousands.

Write a program in Java to input a number and print it in words using the

International System of Numeration

**Example 1:**

Input: 4258746546744

Output: Four Trillion Two Hundred and Fifty Eight Billion Seven Hundred and Forty Six Million Five Hundred and Forty Six Thousand Seven Hundred and Forty Four

**Example 2:**

Input: 4158314

Output: Four Million One Hundred and Fifty Eight Thousand Three Hundred and Fourteen

**Example 3:**

Input: 1000023

Output: One Million and Twenty Three

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 |
import java.io.*; public class Number_2_Words { public String convert(int n) { String wrd[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; if(n>=0&&n<=19) return wrd[n]; return wrd[18+n/10]+' '+wrd[n%10]; } String convert3(int n) { if(n<100) return convert(n); String x = convert(n/100)+" Hundred"; String y = convert(n%100); if(y!="") y = " and "+y; return x+y; } void Int(long n) { String x = ""+n, op = "", w; String nm[] = {"", "Thousand", "Million", "Billion", "Trillion", "Zillion"}; int i, l = x.length(), d, xx; d = l%3; if(d==2) x = 0+x; else if(d==1) x = "00"+x; l = x.length(); d = l/3-1; if(l<=3) op = convert3(Integer.parseInt(x)); else { for(i=0;i<l;i=i+3) { w = x.substring(i, i+3); xx = Integer.parseInt(w); w = convert3(xx); if(w!="") { if(i<l-3) { w = w+' '+nm[d]; op = op+' '+w; } else { w = w+' '+nm[d]; if(xx<100) op = op+" and "+w; else op = op+' '+w; } } d--; } } System.out.println("Output: "+op); } public static void main()throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); long num; System.out.println("Enter a number:"); num = Long.parseLong(r.readLine()); Number_2_Words ob = new Number_2_Words(); ob.Int(num); } } |

## Leave a Reply

You must be logged in to post a comment.