Java program to convert digits into its corresponding words. For Example: 12 = One Two

Below program will convert digits into its corresponding words:

package testjava.controlflow;

public class NumberToWords
{
	public void numberToWords(int number)
	{
		int reverseNumber = reverse(number);
		int digitcount = getDigitCount(number);
		
		System.out.print(number+":");
		while (digitcount > 0)
		{
			int test = reverseNumber % 10;
			
			switch (test)
			{
				case 0:
					System.out.print(" Zero");
					break;	
				case 1:
					System.out.print(" One");
					break;		
				case 2:
					System.out.print(" Two");
					break;	
				case 3:
					System.out.print(" Three");
					break;
				case 4:
					System.out.print(" Four");
					break;
				case 5:
					System.out.print(" Five");
					break;
				case 6:
					System.out.print(" Six");
					break;
				case 7:
					System.out.print(" Seven");
					break;
				case 8:
					System.out.print(" Eight");
					break;
				case 9:
					System.out.print(" Nine");
					break;
			}
	            
			reverseNumber /= 10;
			digitcount--;
		}
		System.out.println();
	}
	
	public static int getDigitCount(int number)
	{
		if(number < 0)
			return -1;
		else if(number == 0)
			return 1;
		
		int count = 0;
		
		while (number != 0)
		{
			number /= 10;
			count++;
		}
		return count;
	}
	
	public static int reverse(int number)
	{
		int result = 0;
		
		while(number != 0)
		{
			result = (result * 10) + number % 10;
			number /= 10;
		}
		return result;
	}
	
	public static void main(String args[])
	{
		NumberToWords ntw = new NumberToWords();
		
		ntw.numberToWords(345);
		ntw.numberToWords(012);
		ntw.numberToWords(456789);
	}		
}

OUTPUT

345: Three Four Five
10: One Zero
456789: Four Five Six Seven Eight Nine