Share this post on:

Here we will write a Program to convert Number into Word in Java.

public class Practice
{

static String one[]={ " ","One","Two","Three","Four","five","Six","Seven",
    "Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fouteen","Fifteen",
    "Sixteen","Seveteen","Eighteen","Nineteen"};

static String Ten[]= {"","","Twenty","Thirty","Fourty","Fifty","Sixty",
    "Seventy","Eighty","Ninety"};

static String numToword(int n,String S)
{
    String str=" ";
    if(n>19)
    {
        str += Ten[n/10] + one[n%10];
    }
    else
    {
        str += one[n];
    }
    if(n!=0)
    {
        str += S;
    }
    return str;
}
static String ConvertToWords(long n)
{
    String out=" ";


    out += numToword((int) (n/10000000)," Crore");
    out += numToword((int) ((n/100000)%100)," Lakh");
    out += numToword((int) ((n/1000)%100)," Thousand");
    out += numToword((int) ((n/100%10))," Hundred");

    if(n>100 && n%100>0)
    {
        out += " and";
    }
    out +=  numToword((int) (n%100)," ");
    return out;

}
public static void main(String[] args)
{
    long n=15243;
    System.out.println(ConvertToWords(n));

}
}

Output:

  Fifteen Thousand Two Hundred and FourtyThree 
Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

Leave a Comment

Your email address will not be published. Required fields are marked *