Rewrite numbers as words using Core JAVA

Very often application developers come across scenarios to Rewrite numbers as words while generating invoice or bills in their applications. This Code will represent the numbers as words in English language. The logic is developed in simple core JAVA. This piece of code can be copied in to a class file.

import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class NumToWord {
    private static final String[] tensnames = new String[]{"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
    private static final String[] one_to_nineteen = new String[]{"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};

    private String numtoword(int number, boolean alpha, boolean uppercase) {
        String result = "";
        if (!alpha) {
            return "" + number + "";
        }
        if (number % 100 < 20) {
            result = one_to_nineteen[number];
            number /= 100;
        } else {
            result = one_to_nineteen[number % 10];
            result = result == "" ? tensnames[number % 10] + result : tensnames[(number /= 10) % 10] + "-" + result;
            number /= 10;
        }
        if (number == 0) {
            if (uppercase) {
                return this.ToUppercase(result);
            }
            return result;
        }
        result = number / 10 == 0 ? one_to_nineteen[number % 10] + " hundred " + result : one_to_nineteen[number % 10] + " hundred and " + result;
        if ((number /= 10) == 0) {
            if (uppercase) {
                return this.ToUppercase(result);
            }
            return result;
        }
        if (number < 20) {
            result = one_to_nineteen[number] + " thousand " + result;
        } else {
            result = one_to_nineteen[number % 10] + " thousand " + result;
            result = tensnames[number /= 10] + "-" + result;
        }
        if (uppercase) {
            return this.ToUppercase(result);
        }
        return result;
    }

    public String ToUppercase(String result) {
        char firstindex = Character.toUpperCase(result.charAt(0));
        String resultUpper = result.substring(1, result.length());
        return "" + firstindex + resultUpper;
    }

Now, call the NumToword() method from anywhere in the application and pass the required parameters. This methods returns the Currency or number in word format.

Happy Coding.