Number To Word In Java

//NUMBER TO WORD
class Number2Word{
    private String a1[]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fiteen","Sixteen","Seventeen","Eighteen","Nineteen"};
    private String a2[]={"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
    public void display(int n){
        if(n<=19)
        f1(n);
        else if(n<=99)
        f2(n);
        else
        f3(n);
    }
    public void f1(int n){
        System.out.println(a1[n]);
    }
    public void f2(int n){
        int x,y;
        x=n/10;
        y=n%10;
        if(y==0)
        System.out.println(a2[x-2]);
        else
        System.out.println(a2[x-2]+" "+a1[y]);
    }
    public void f3(int n){
        int x,y;
        x=n/100;
        y=n%100;
        System.out.print(a1[x]+" "+"Hundred"+" ");
        if(y==0)
        System.out.println();
        else{
            System.out.print("And ");
            if(y<=19)
            f1(y);
            else
            f2(y);
        }
    }
}
       
     

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Lucky Number In Java ISC

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.