Code Below:


import java.util.*;
class numtowrd
{
    public static void main()
    {
        Scanner s=new Scanner(System.in);
        System.out.println("Enter your number");
        int n=s.nextInt();
        int th,h,t,u;
        if (n< 0 || n>9999)
        {
            System.out.println("Invalid Inputs");
            System.exit(0);
        }
        String arr[]={"","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)
        System.out.println("ZERO");
        else
        {
            th=n/1000;
            if (th>0)
            System.out.print(arr[th]+" THOUSAND ");
            n=n%1000;
            
            h=n/100;
            if (h>0)
            System.out.print(arr[h]+" HUNDRED ");
            n=n%100;
            
            if (n<=19)
            System.out.print(arr[n]);
            else
            {
                t=n/10;
                u=n%10;
                System.out.print(arr[18+t]+" "+arr[u]);
            }
        }
    }
}